Simple abstract unified memory management layer designed for resource-constrained systems.
More...
|
| file | memory.h |
| | Functions and prototypes for managing memory.
|
| |
| file | fakem.h |
| | Platform-overridden typedefs and macros for handling memory.
|
| |
|
|
typedef struct FAKE_MEMORY_HANDLE * | MEMORY_HANDLE |
| | A reference to a block of memory which the operating system may move around on its own to free up space. MUST BE locked with memory_lock() to receive a MEMORY_PTR that can be dereferenced.
|
| |
| typedef void * | MEMORY_PTR |
| | A C-style memory pointer that can be safely dereferenced.
|
| |
|
typedef const void * | CONST_MEMORY_PTR |
| | A read-only MEMORY_PTR.
|
| |
|
typedef void * | MEMORY_FAR_PTR |
| | On certain platforms, a MEMORY_PTR that exists outside of the current page.
|
| |
|
typedef const void * | CONST_MEMORY_FAR_PTR |
| | A read-only MEMORY_FAR_PTR.
|
| |
|
|
int32_t | memory_init () |
| |
| MEMORY_HANDLE | memory_alloc (uint32_t sz, uint32_t count) |
| | Request dynamic memory from operating system while protecting from overflow conditions.
|
| |
| void | memory_free (MEMORY_HANDLE handle) |
| | Free a block of dynamic memory previously allocated with memory_alloc().
|
| |
|
uint32_t | memory_sz (MEMORY_HANDLE) |
| |
|
uint32_t | memory_resize (MEMORY_HANDLE *, uint32_t) |
| |
|
void | memory_copy_ptr (MEMORY_PTR, CONST_MEMORY_PTR, uint32_t) |
| |
| void | memory_zero_ptr (MEMORY_PTR ptr, uint32_t sz) |
| | Fill a block of memory with zeros.
|
| |
| WARN_UNUSED MEMORY_PTR | memory_unlock (MEMORY_HANDLE handle) |
| | Unlock a dynamic memory handle so the system can relocate it on the heap to relieve congestion.
|
| |
|
char * | memory_strncpy_ptr (char *, const char *, uint16_t) |
| |
|
int16_t | memory_strncmp_ptr (const char *, const char *, uint16_t) |
| |
| int16_t | memory_strnlen_ptr (const char *s, uint16_t l) |
| | Get the size of a string, up to a specified maximum.
|
| |
|
void | memory_debug_dump () |
| |
| WARN_UNUSED MEMORY_PTR | memory_lock (MEMORY_HANDLE handle) |
| | Lock a dynamic memory handle and return a MEMORY_PTR that can be dereferenced safely.
|
| |
Simple abstract unified memory management layer designed for resource-constrained systems.
◆ MEMORY_PTR
A C-style memory pointer that can be safely dereferenced.
Interchangeable with pointers to arbitrary types (e.g. char*, int*, etc).
◆ memory_alloc()
Request dynamic memory from operating system while protecting from overflow conditions.
- Parameters
-
| sz | Size of blocks to request. |
| count | Number of blocks to request. |
- Returns
- A MEMORY_HANDLE to allocated memory. This handle MUST BE locked to receive a MEMORY_PTR that can be dereferenced safely.
◆ memory_free()
Free a block of dynamic memory previously allocated with memory_alloc().
- Parameters
-
◆ memory_lock()
Lock a dynamic memory handle and return a MEMORY_PTR that can be dereferenced safely.
- Parameters
-
| handle | A handle that has been successfully allocated with memory_alloc(). |
- Returns
- A typical C-style pointer that can be dereferenced as normal.
◆ memory_strnlen_ptr()
| int16_t memory_strnlen_ptr |
( |
const char * | s, |
|
|
uint16_t | l ) |
Get the size of a string, up to a specified maximum.
- Parameters
-
| s | MEMORY_PTR to a string to get the size of. |
| l | Maximum possible size of string s. |
- Returns
- Position of the NULL terminator in string s, or if none is found under l characters, l.
◆ memory_unlock()
Unlock a dynamic memory handle so the system can relocate it on the heap to relieve congestion.
- Parameters
-
| handle | A handle that has been previously locked with memory_lock(). |
- Returns
- NULL if the unlock was successful.
◆ memory_zero_ptr()
| void memory_zero_ptr |
( |
MEMORY_PTR | ptr, |
|
|
uint32_t | sz ) |
Fill a block of memory with zeros.
- Parameters
-
| ptr | MEMORY_PTR to a block of memory to overwrite. May be on the stack or a MEMORY_PTR returned from locking a MEMORY_HANDLE. |
| sz | Size of the block of memory to overwrite. |