Main Page

Macros | Functions
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

## § avr_new

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

Macro for allocating memory.

Parameters

  type | The C type of the memory to allocate.
  count | Allocate 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().

## § avr_new0

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

Macro for allocating memory and initializing it to zero.

Parameters

  type | The C type of the memory to allocate.
  count | Allocate 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 display_send_msg(), mem_construct(), mem_new(), and vdev_new().

## § avr_renew

#define avr_renew | ( |  | type,
|  |  | mem,
|  |  | count
| ) |  | ((type *) avr_realloc (mem, (unsigned) sizeof (type) * (count)))

Macro for allocating memory.

Parameters

  type | The C type of the memory to allocate.
  mem | Pointer to existing memory.
  count | Allocate 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

## § avr_malloc()

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.

## § avr_malloc0()

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.

## § avr_realloc()

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.

## § avr_strdup()

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.

## § avr_free()

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

Automatically generated by Doxygen 1.8.12 on Tue Apr 18 2017.