simulavr  1.1.0
avrmalloc.cpp File Reference
#include <stdlib.h>
#include <string.h>
#include "avrerror.h"
#include "avrmalloc.h"

Go to the source code of this file.

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...
 

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.