libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
MemSpace Class Reference

Abstraction for memory allocation in different address spaces. More...

#include <memspace.h>

Classes

struct  Ops
 Function table for memory space operations. More...
 

Public Types

enum  ID { System = 0 , SystemSecure , Default = System }
 Identifies a memory space. More...
 

Public Member Functions

 MemSpace (ID id=Default)
 Constructs a MemSpace for the given memory space ID.
 
const Stringname () const
 Returns the human-readable name of this memory space.
 
ID id () const
 Returns the memory space identifier.
 
bool isHostAccessible (const MemAllocation &alloc) const
 Returns true if the given allocation is directly accessible from the host CPU.
 
MemAllocation alloc (size_t bytes, size_t align) const
 Allocates memory in this memory space.
 
void release (MemAllocation &alloc) const
 Releases a previously allocated memory region.
 
bool copy (const MemAllocation &src, const MemAllocation &dst, size_t bytes) const
 Copies bytes from a source allocation to a destination allocation.
 
Error fill (void *ptr, size_t bytes, char value) const
 Fills memory with a byte value.
 

Detailed Description

Abstraction for memory allocation in different address spaces.

Provides a uniform interface for allocating, releasing, copying, and setting memory that may reside in different memory spaces (e.g. system RAM, GPU memory). Each memory space is identified by an ID and provides its own set of operations.

Memory spaces handle their own lifecycle concerns internally. For example, SystemSecure performs page locking on allocation and secure zeroing on release without exposing those details through the MemSpace API.

Member Enumeration Documentation

◆ ID

Identifies a memory space.

Enumerator
System 

System (CPU) memory.

SystemSecure 

System memory with secure zeroing on free and page locking.

Default 

Alias for System memory.

Constructor & Destructor Documentation

◆ MemSpace()

MemSpace::MemSpace ( ID  id = Default)
inline

Constructs a MemSpace for the given memory space ID.

Parameters
idThe memory space to use (default: Default).

Member Function Documentation

◆ alloc()

MemAllocation MemSpace::alloc ( size_t  bytes,
size_t  align 
) const
inline

Allocates memory in this memory space.

Parameters
bytesNumber of bytes to allocate.
alignRequired alignment in bytes.
Returns
A MemAllocation describing the allocated region.

◆ copy()

bool MemSpace::copy ( const MemAllocation src,
const MemAllocation dst,
size_t  bytes 
) const
inline

Copies bytes from a source allocation to a destination allocation.

Called on the source's MemSpace. The source and destination may reside in different memory spaces.

Parameters
srcThe source allocation.
dstThe destination allocation.
bytesNumber of bytes to copy.
Returns
True on success, false if either pointer is nullptr.

◆ fill()

Error MemSpace::fill ( void ptr,
size_t  bytes,
char  value 
) const
inline

Fills memory with a byte value.

Parameters
ptrDestination pointer.
bytesNumber of bytes to fill.
valueThe byte value to fill with.
Returns
Error::Ok on success, or an error if ptr is nullptr.

◆ id()

ID MemSpace::id ( ) const
inline

Returns the memory space identifier.

Returns
The ID.

◆ isHostAccessible()

bool MemSpace::isHostAccessible ( const MemAllocation alloc) const
inline

Returns true if the given allocation is directly accessible from the host CPU.

Parameters
allocThe allocation to check.
Returns
True if the memory can be directly read/written by the CPU.

◆ name()

const String & MemSpace::name ( ) const
inline

Returns the human-readable name of this memory space.

Returns
The name string.

◆ release()

void MemSpace::release ( MemAllocation alloc) const
inline

Releases a previously allocated memory region.

Parameters
allocThe allocation to release. Cleared on return.

The documentation for this class was generated from the following file: