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

Copyright
  Copyright 2026 by Jonathan W. Valvano, valva.nosp@m.no@m.nosp@m.ail.u.nosp@m.texa.nosp@m.s.edu,

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

  desiredBytes | desired 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

  pointer | to 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

  desiredBytes | desired 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

  oldBlock | pointer to a block
  desiredBytes | a 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

  reference | to 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)