pub unsafe fn memory_allocate(
_: *mut c_void,
size: usize,
alignment: usize,
capabilities: MemoryCapabilities,
) -> *mut c_voidExpand description
Allocates a memory block with specified properties.
This function allocates a block of memory with the specified size, alignment, and capabilities. The memory is uninitialized and must be properly initialized before use.
§Safety
This function is unsafe because:
- The returned memory is uninitialized
- The caller must ensure proper deallocation
- The hint address, if provided, must be a valid memory address
§Parameters
Hint_address- Preferred memory address (hint only, may be ignored), or nullSize- Size of the memory block in bytes. On 32-bit targets a block, including its header and padding, is limited to 32 MiB.Alignment- Required memory alignment in bytes (must be a power of 2)Capabilities- Memory capabilities flags (seememory_capabilities_*constants)
§Returns
- Pointer to the allocated memory block
- Null if allocation fails
§Errors
Returns null if:
- Insufficient memory available
- Invalid alignment (not a power of 2)
- Requested capabilities not supported
- Size is too large
§Examples
// Allocate 1024 bytes with 8-byte alignment
void* ptr = memory_allocate(NULL, 1024, 8, memory_capabilities_none);
// Allocate executable memory for code
void* code_ptr = memory_allocate(NULL, 4096, 4096, MEMORY_CAPABILITIES_EXECUTE);
// Allocate DMA-capable memory
void* dma_ptr = memory_allocate(NULL, 2048, 32, memory_capabilities_direct_memory_access);