Muteki
EABI code execution on Besta® RTOS devices.
Loading...
Searching...
No Matches
memory.h File Reference

Memory management API. More...

#include "common.h"

Go to the source code of this file.

Functions

void * lmalloc (size_t size)
 Allocate heap memory.
void * lcalloc (size_t nmemb, size_t size)
 Allocate and clear data units on the heap.
void * lrealloc (void *ptr, size_t size)
 Resize or reallocate memory.
void _lfree (void *ptr)
 Free previously allocated memory.
size_t GetFreeMemory (void)
 Return the size of available memory.

Detailed Description

Memory management API.

In Besta RTOS, heap memory management is entirely done in the OS kernel. All applications share a single heap managed by the OS and can be accessed through the malloc series API. Conventional address-space based heap memory management such as sbrk() is not supported due to the absence of MMU support in the OS kernel.

The simplest way to get heap memory support in a custom libc is to redirect malloc(), calloc(), realloc() and free() to the corresponding functions provided here.

Function Documentation

◆ _lfree()

void _lfree ( void * ptr)
extern

Free previously allocated memory.

Parameters
ptrPointer to previously allocated memory.
Returns
None.

◆ GetFreeMemory()

size_t GetFreeMemory ( void )
extern

Return the size of available memory.

Requires -lkrnllib when dynamically linking with the shims.

Parameters
None.
Returns
Size of available memory.

◆ lcalloc()

void * lcalloc ( size_t nmemb,
size_t size )
extern

Allocate and clear data units on the heap.

Parameters
nmembNumber of data units to allocate.
sizeSize of each data unit.
Returns
Pointer to allocated memory, or NULL if allocation fails.

◆ lmalloc()

void * lmalloc ( size_t size)
extern

Allocate heap memory.

Parameters
sizeSize of the allocation in bytes.
Returns
Pointer to allocated memory, or NULL if allocation fails.

◆ lrealloc()

void * lrealloc ( void * ptr,
size_t size )
extern

Resize or reallocate memory.

Parameters
ptrPointer to previously allocated memory.
sizeNew size in bytes.
Returns
Pointer to the newly allocated memory, or NULL if allocation fails.