Go to the source code of this file.
Defines | |
#define | avr_new(type, count) ((type *) avr_malloc ((unsigned) sizeof (type) * (count))) |
#define | avr_new0(type, count) ((type *) avr_malloc0 ((unsigned) sizeof (type) * (count))) |
#define | avr_renew(type, mem, count) ((type *) avr_realloc (mem, (unsigned) sizeof (type) * (count))) |
Functions | |
void * | avr_malloc (size_t size) |
void * | avr_malloc0 (size_t size) |
void * | avr_realloc (void *ptr, size_t size) |
char * | avr_strdup (const char *s) |
void | avr_free (void *ptr) |
This module provides facilities for managing memory.
There is no need to check the returned values from any of these functions. Any memory allocation failure is considered fatal and the program is terminated.
We want to wrap all functions that allocate memory. This way we can add secret code to track memory usage and debug memory leaks if we want. Right now, I don't want to ;).
Definition in file avrmalloc.c.
#define avr_new | ( | type, | |||
count | ) | ((type *) avr_malloc ((unsigned) sizeof (type) * (count))) |
Macro for allocating memory.
type | The C type of the memory to allocate. | |
count | Allocate enough memory hold count types. |
Definition at line 57 of file avrmalloc.c.
Referenced by adc_intr_new(), adc_new(), avr_core_new(), class_new(), flash_new(), hwstack_new(), memstack_new(), ocreg16_new(), spi_intr_new(), spi_new(), stack_new(), timer0_new(), timer16_new(), timer_intr_new(), uart_intr_new(), uart_new(), usb_intr_new(), and usb_new().
#define avr_new0 | ( | type, | |||
count | ) | ((type *) avr_malloc0 ((unsigned) sizeof (type) * (count))) |
Macro for allocating memory and initializing it to zero.
type | The C type of the memory to allocate. | |
count | Allocate enough memory hold count types. |
Definition at line 67 of file avrmalloc.c.
Referenced by decode_init_lookup_table(), display_send_msg(), hwstack_construct(), mem_construct(), mem_new(), and vdev_new().
#define avr_renew | ( | type, | |||
mem, | |||||
count | ) | ((type *) avr_realloc (mem, (unsigned) sizeof (type) * (count))) |
Macro for allocating memory.
type | The C type of the memory to allocate. | |
mem | Pointer to existing memory. | |
count | Allocate enough memory hold count types. |
Definition at line 78 of file avrmalloc.c.
void* avr_malloc | ( | size_t | size | ) |
Allocate memory and initialize to zero.
Use the avr_new() macro instead of this function.
There is no need to check the returned value, since this function will terminate the program if the memory allocation fails.
No memory is allocated if passed a size of zero.
Definition at line 93 of file avrmalloc.c.
References avr_error.
void* avr_malloc0 | ( | size_t | size | ) |
Allocate memory and initialize to zero.
Use the avr_new0() macro instead of this function.
There is no need to check the returned value, since this function will terminate the program if the memory allocation fails.
No memory is allocated if passed a size of zero.
Definition at line 117 of file avrmalloc.c.
References avr_error.
void* avr_realloc | ( | void * | ptr, | |
size_t | size | |||
) |
Wrapper for realloc(). x Resizes and possibly allocates more memory for an existing memory block.
Use the avr_renew() macro instead of this function.
There is no need to check the returned value, since this function will terminate the program if the memory allocation fails.
No memory is allocated if passed a size of zero.
Definition at line 143 of file avrmalloc.c.
References avr_error.
char* avr_strdup | ( | const char * | s | ) |
Wrapper for strdup().
Returns a copy of the passed in string. The returned copy must be free'd.
There is no need to check the returned value, since this function will terminate the program if the memory allocation fails.
It is safe to pass a NULL pointer. No memory is allocated if a NULL is passed.
Definition at line 168 of file avrmalloc.c.
References avr_error.
void avr_free | ( | void * | ptr | ) |
Free malloc'd memory.
It is safe to pass a null pointer to this function.
Definition at line 187 of file avrmalloc.c.
Referenced by class_destroy(), display_send_msg(), and hwstack_destroy().