simulavr  1.1.0
avrmalloc.h File Reference

Go to the source code of this file.

Macros

#define avr_new(type, count)   ((type *) avr_malloc ((unsigned) sizeof (type) * (count)))
 Macro for allocating memory. More...
 
#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)
 Memory Management Functions. More...
 
void * avr_malloc0 (size_t size)
 Allocate memory and initialize to zero. More...
 
void * avr_realloc (void *ptr, size_t size)
 Wrapper for realloc(). More...
 
char * avr_strdup (const char *s)
 Wrapper for strdup(). More...
 
void avr_free (void *ptr)
 Free malloc'd memory. More...
 

Macro Definition Documentation

◆ avr_new

#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 40 of file avrmalloc.h.

Referenced by FlashProgramming::FlashProgramming(), Memory::GetAddressAtSymbol(), Memory::Memory(), and ThreeLevelStack::ThreeLevelStack().

◆ avr_new0

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

Definition at line 43 of file avrmalloc.h.

◆ avr_renew

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

Definition at line 46 of file avrmalloc.h.

Function Documentation

◆ 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 182 of file avrmalloc.cpp.

Referenced by Memory::GetAddressAtSymbol(), FlashProgramming::~FlashProgramming(), HWEeprom::~HWEeprom(), Memory::~Memory(), and ThreeLevelStack::~ThreeLevelStack().

◆ avr_malloc()

void* avr_malloc ( size_t  size)

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 ;). 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 92 of file avrmalloc.cpp.

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 115 of file avrmalloc.cpp.

References avr_error.

◆ avr_realloc()

void* avr_realloc ( void *  ptr,
size_t  size 
)

Wrapper for realloc().

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 140 of file avrmalloc.cpp.

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 164 of file avrmalloc.cpp.

References avr_error.