Function xila_memory_allocate

Source
#[no_mangle]
pub unsafe extern "C" fn xila_memory_allocate(
    _: *mut c_void,
    size: usize,
    alignment: usize,
    capabilities: XilaMemoryCapabilities,
) -> *mut c_void
Expand 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 providalignment enumed, must be a valid memory address

§Parameters

  • Hint_address - Preferred memory address (hint only, may be ignored), or null
  • Size - Size of the memory block in bytes
  • Alignment - Required memory alignment in bytes (must be a power of 2)
  • Capabilities - Memory capabilities flags (see xila_memory_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 = xila_memory_allocate(NULL, 1024, 8, xila_memory_capabilities_none);

// Allocate executable memory for code
void* code_ptr = xila_memory_allocate(NULL, 4096, 4096, XILA_MEMORY_CAPABILITIES_EXECUTE);

// Allocate DMA-capable memory
void* dma_ptr = xila_memory_allocate(NULL, 2048, 32, xila_memory_capabilities_direct_memory_access);