dsekai
World engine for retrocomputers.
Loading...
Searching...
No Matches
Files | Data Structures | Typedefs | Functions
Unilayer Memory Layer

Simple abstract unified memory management layer designed for resource-constrained systems. More...

Files

file  memory.h
 Functions and prototypes for managing memory.
 
file  fakem.h
 Platform-overridden typedefs and macros for handling memory.
 

Data Structures

struct  FAKE_MEMORY_HANDLE
 An emulated memory handle for modern systems. Overridden on most platforms. More...
 

Typedefs

typedef struct FAKE_MEMORY_HANDLEMEMORY_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.
 

Functions

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.
 

Detailed Description

Simple abstract unified memory management layer designed for resource-constrained systems.

Typedef Documentation

◆ MEMORY_PTR

typedef void* MEMORY_PTR

A C-style memory pointer that can be safely dereferenced.

Interchangeable with pointers to arbitrary types (e.g. char*, int*, etc).

Function Documentation

◆ memory_alloc()

MEMORY_HANDLE memory_alloc ( uint32_t  sz,
uint32_t  count 
)

Request dynamic memory from operating system while protecting from overflow conditions.

Parameters
szSize of blocks to request.
countNumber 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()

void memory_free ( MEMORY_HANDLE  handle)

Free a block of dynamic memory previously allocated with memory_alloc().

Parameters
handleMEMORY_HANDLE to a previously allocated memory block.

◆ memory_lock()

WARN_UNUSED MEMORY_PTR memory_lock ( MEMORY_HANDLE  handle)

Lock a dynamic memory handle and return a MEMORY_PTR that can be dereferenced safely.

Parameters
handleA 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
sMEMORY_PTR to a string to get the size of.
lMaximum 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()

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.

Parameters
handleA 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
ptrMEMORY_PTR to a block of memory to overwrite. May be on the stack or a MEMORY_PTR returned from locking a MEMORY_HANDLE.
szSize of the block of memory to overwrite.