avrmalloc.c File Reference

Go to the source code of this file.

Macros

#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)
 

Detailed Description

Memory Management Functions.

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.

Macro Definition Documentation

#define avr_new (   type,
  count 
)    ((type *) avr_malloc ((unsigned) sizeof (type) * (count)))

Macro for allocating memory.

Parameters
typeThe C type of the memory to allocate.
countAllocate enough memory hold count types.

This macro is just a wrapper for avr_malloc() and should be used to avoid the repetitive task of casting the returned pointer.

Definition at line 57 of file avrmalloc.c.

Referenced by avr_core_new(), class_new(), flash_new(), hwstack_new(), memstack_new(), and stack_new().

#define avr_new0 (   type,
  count 
)    ((type *) avr_malloc0 ((unsigned) sizeof (type) * (count)))

Macro for allocating memory and initializing it to zero.

Parameters
typeThe C type of the memory to allocate.
countAllocate enough memory hold count types.

This macro is just a wrapper for avr_malloc0() and should be used to avoid the repetitive task of casting the returned pointer.

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.

Parameters
typeThe C type of the memory to allocate.
memPointer to existing memory.
countAllocate enough memory hold count types.

This macro is just a wrapper for avr_malloc() and should be used to avoid the repetitive task of casting the returned pointer.

Definition at line 78 of file avrmalloc.c.

Function Documentation

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(), hwstack_destroy(), and mem_destroy().


Automatically generated by Doxygen 1.8.2 on Sat Mar 7 2015.