AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
Functions
MemUtils Namespace Reference

A namespace providing encapsulation for functions that report the available memory in SRAM. More...

Functions

size_t freeSRAM ()
 Get the total free memory remaining in SRAM. More...
 
size_t freeMemoryBetweenHeapAndStack ()
 Get the free memory between the heap and the stack. More...
 
void resetHeap ()
 Reset the heap to an empty (virgin) state. More...
 
size_t memoryAvailableOnFreeList ()
 Get the free memory on the heap free-list. More...
 
size_t getFreeListStats (int *nbrBlocks, size_t *sizeSmallestBlock, size_t *sizeLargestBlock)
 Get information about the heap free-list. More...
 

Detailed Description

A namespace providing encapsulation for functions that report the available memory in SRAM.

Function Documentation

§ freeMemoryBetweenHeapAndStack()

size_t MemUtils::freeMemoryBetweenHeapAndStack ( )

Get the free memory between the heap and the stack.

This does not include any memory potentially available within the heap on the free-list. It executes quickly, so this function is useful for checking to make sure the heap and stack aren't in danger of collision.

Returns
The number of free bytes remaining between the top of the heap and the top of the stack.

§ freeSRAM()

size_t MemUtils::freeSRAM ( )

Get the total free memory remaining in SRAM.

This includes memory on the free-list (if the heap is used) as well as memory available between the heap and the stack (which grow towards each other). If the heap has been used, the function will walk the free-list to determine the total amount of free memory.

Returns
The number of free bytes remaining in SRAM.

§ getFreeListStats()

size_t MemUtils::getFreeListStats ( int *  nbrBlocks,
size_t *  sizeSmallestBlock,
size_t *  sizeLargestBlock 
)

Get information about the heap free-list.

This provides information about the number of blocks on the free list, the size of the largest and smallest block, as well as the total memory held on the free list.

Note
This does NOT include any unallocated memory available between the top of the heap and the top of the stack.
  • nbrBlocks returns the number of blocks in the free-list.
  • sizeSmallestBlock returns the size of the smallest block on the free-list.
  • answerGeneralCall returns the size of the largest block on the free-list.
Returns
The total number of free bytes on the heap's free list.

§ memoryAvailableOnFreeList()

size_t MemUtils::memoryAvailableOnFreeList ( )

Get the free memory on the heap free-list.

This shows the total free memory available on the free-list. This is the sum of the free-blocks contained within the heap.

Note
This does NOT include any unallocated memory available between the top of the heap and the top of the stack.
Returns
The total number of free bytes on the heap's free-list.

§ resetHeap()

void MemUtils::resetHeap ( )

Reset the heap to an empty (virgin) state.

This function resets the heap to an empty, pristine state. Not only are all memory allocations abandoned, but the free list is also purged, leaving everything between the start of the heap and the top of the stack as unallocated (actually, never-allocated) memory.