|
muteki
|
Memory management API. More...
#include <muteki/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. | |
| void * | AllocBlock (size_t size, unsigned short tag, bool new_segment) |
| Allocate memory on the secondary heap. | |
| void | FreeBlock (void *ptr) |
| Free memory previously allocated with AllocBlock(). | |
| size_t | GetFreeMemory (void) |
| Return the size of available memory. | |
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.
|
extern |
Free previously allocated memory.
| ptr | Pointer to previously allocated memory. |
|
extern |
Allocate memory on the secondary heap.
This allocates a block of memory on a secondary heap, that may be backed by a large block of memory on the primary heap. This secondary heap is usually 64KiB in size.
This seems to have a tie to the UI subsystem as UI-related syscalls seem to use this extensively.
0x10145| size | Size of the memory. |
| tag | Write this value to <allocated address> + 0x30 when the allocated memory is located on a fresh chunk (i.e. allocated on previously unused memory directly following the last chunk). Seems to be used in UI subsystem to differentiate components in some circumstances. |
| new_segment | Set to true to start a new segment. This will prevent this chunk and all chunks above from being reused until this memory is freed. |
|
extern |
Free memory previously allocated with AllocBlock().
If a segment chunk is freed, everything below it will also be implicitly freed.
0x10146 | ptr | Pointer to previously allocated memory. |
|
extern |
Return the size of available memory.
Requires -lkrnllib when dynamically linking with the shims.
|
extern |
Allocate and clear data units on the heap.
| nmemb | Number of data units to allocate. |
| size | Size of each data unit. |
NULL if allocation fails.
|
extern |
Allocate heap memory.
| size | Size of the allocation in bytes. |
NULL if allocation fails.
|
extern |
Resize or reallocate memory.
| ptr | Pointer to previously allocated memory. |
| size | New size in bytes. |
NULL if allocation fails.