RTOS_MSPM0  1.1
ECE445M starter code
Data Structures | Typedefs | Functions
heap.h File Reference

heap memory manager More...

#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  heap_stats
 

Typedefs

typedef struct heap_stats heap_stats_t
 

Functions

int32_t Heap_Init (void)
 Initializes/resets the heap to a clean state where no memory is allocated. More...
 
void * Heap_Malloc (int32_t desiredBytes)
 Allocate memory. More...
 
void * Heap_Calloc (int32_t desiredBytes)
 Zero-allocate memory. More...
 
void * Heap_Realloc (void *oldBlock, int32_t desiredBytes)
 Grow/shrink memory. More...
 
int32_t Heap_Free (void *pointer)
 Free memory. More...
 
int32_t Heap_Stats (heap_stats_t *stats)
 Get heap usage. More...
 

Detailed Description

heap memory manager

Dynamic memory management on a heap

Version
V1.0
Author
Valvano (originally by Jacob Egner)
Warning
AS-IS
Note
For more information see http://users.ece.utexas.edu/~valvano/
Date
Jan 10, 2026

Function Documentation

◆ Heap_Calloc()

void* Heap_Calloc ( int32_t  desiredBytes)

Zero-allocate memory.

Allocate memory, allocated memory is initialized to 0 (zeroed out)

Parameters
desiredBytesdesired number of bytes to allocate
Returns
void* pointing to the allocated memory block or will return NULL if there isn't sufficient space to satisfy allocation request

◆ Heap_Free()

int32_t Heap_Free ( void *  pointer)

Free memory.

Return a block to the heap

Parameters
pointerto memory to unallocate
Returns
0 if everything is ok, non-zero in case of error (e.g. invalid pointer or trying to unallocate memory that has already been unallocated)

◆ Heap_Init()

int32_t Heap_Init ( void  )

Initializes/resets the heap to a clean state where no memory is allocated.

Initialize the Heap

Parameters
none
Returns
always 0 (success)

◆ Heap_Malloc()

void* Heap_Malloc ( int32_t  desiredBytes)

Allocate memory.

Allocate memory, data not initialized

Parameters
desiredBytesdesired number of bytes to allocate
Returns
void* pointing to the allocated memory or will return NULL if there isn't sufficient space to satisfy allocation request

◆ Heap_Realloc()

void* Heap_Realloc ( void *  oldBlock,
int32_t  desiredBytes 
)

Grow/shrink memory.

Reallocate buffer to a new size. The given block may be unallocated and its contents copied to a new block

Parameters
oldBlockpointer to a block
desiredBytesa desired number of bytes for a new block
Returns
void* pointing to the new block or will return NULL if there is any reason the reallocation can't be completed

◆ Heap_Stats()

int32_t Heap_Stats ( heap_stats_t stats)

Get heap usage.

Return the current usage status of the heap

Parameters
referenceto a heap_stats_t that returns the current usage of the heap
Returns
0 in case of success, non-zeror in case of error (e.g. corrupted heap)