API for doing dynamic memory allocation.


This provides malloc()/free() functionality with locking. The shared resource heap needs to be protected from concurrent access when OS has been started. os_malloc() function grabs a mutex before calling malloc().


void *os_malloc(size_t size)

Operating system level malloc().

This ensures that a safe malloc occurs within the context of the OS. Depending on platform, the OS may rely on libc’s malloc() implementation, which is not guaranteed to be thread-safe. This malloc() will always be thread-safe.


A pointer to the memory region allocated.

  • size: The number of bytes to allocate

void os_free(void *mem)

Operating system level free().

See description of os_malloc() for reasoning.

Free’s memory allocated by malloc.

  • mem: The memory to free.

void *os_realloc(void *ptr, size_t size)

Operating system level realloc().

See description of os_malloc() for reasoning.

Reallocates the memory at ptr, to be size contiguouos bytes.


A pointer to memory of size, or NULL on failure to allocate

  • ptr: A pointer to the memory to allocate

  • size: The number of contiguouos bytes to allocate at that location