pub struct Manager<'a>(/* private fields */);Expand description
A wrapper type that adapts any type implementing Allocator_trait to the standard
Rust GlobalAlloc trait.
This enables custom allocators that implement the Xila-specific Allocator_trait
to be used as the global memory allocator for Rust’s allocation system.
Implementations§
Source§impl<'a> Manager<'a>
impl<'a> Manager<'a>
Sourcepub const fn new(allocator: &'a dyn ManagerTrait) -> Manager<'a>
pub const fn new(allocator: &'a dyn ManagerTrait) -> Manager<'a>
Sourcepub unsafe fn allocate(
&self,
capabilities: CapabilityFlags,
layout: Layout,
) -> *mut u8
pub unsafe fn allocate( &self, capabilities: CapabilityFlags, layout: Layout, ) -> *mut u8
Allocates memory with the specified capabilities and layout.
§Parameters
Capabilities- Specific requirements for the allocationLayout- Size and alignment requirements for the allocation
§Returns
A pointer to the allocated memory, or a null pointer if allocation failed.
§Safety
This function is unsafe because the caller must ensure that:
Sourcepub unsafe fn deallocate(&self, pointer: *mut u8, layout: Layout)
pub unsafe fn deallocate(&self, pointer: *mut u8, layout: Layout)
Deallocates memory previously allocated by this allocator.
§Parameters
Pointer- Pointer to the memory to deallocateLayout- The layout that was used to allocate the memory
§Safety
This function is unsafe because the caller must ensure that:
- The pointer was allocated by this allocator
- The layout matches the layout used for allocation
Sourcepub unsafe fn reallocate(
&self,
capabilities: CapabilityFlags,
pointer: *mut u8,
layout: Layout,
new_size: usize,
) -> *mut u8
pub unsafe fn reallocate( &self, capabilities: CapabilityFlags, pointer: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8
Resizes memory with its original alignment and capabilities.
A null pointer requests a fresh allocation. On success, the contents of the old block are preserved up to the smaller of the old and new sizes. On failure, the original block remains valid.
§Parameters
capabilities- The capability requirements of the allocationPointer- Pointer to the memory to reallocate. If null, acts as a new allocationOld_layout- The layout that was used for the original allocationNew_size- The new size for the memory
§Returns
A pointer to the reallocated memory with the new layout, or a null pointer if reallocation failed.
§Safety
This function is unsafe because the caller must ensure that:
- If
Pointeris not null, it was allocated by this allocator - The layout and capabilities match those used for the original allocation
- The old memory is not used after successful reallocation
- The returned memory is properly initialized before use
pub fn get_page_size(&self) -> usize
pub fn flush_data_cache(&self)
Sourcepub unsafe fn flush_instruction_cache(&self, address: *const u8, size: usize)
pub unsafe fn flush_instruction_cache(&self, address: *const u8, size: usize)
Flushes the instruction cache for the specified memory region.
§Parameters
Address- Starting address of the memory regionSize- Size of the memory region in bytes
§Safety
This function is unsafe because the caller must ensure that:
- The address is valid and points to a memory region of at least
sizebytes - The memory region is not being modified while the instruction cache is being flushed
Sourcepub fn get_free(&self) -> usize
pub fn get_free(&self) -> usize
Returns the amount of memory currently available.
§Returns
The number of bytes available for allocation.
Sourcepub fn get_total_size(&self) -> usize
pub fn get_total_size(&self) -> usize
Returns the total size of the memory managed by this allocator.
§Returns
The total number of bytes managed by the allocator.
Trait Implementations§
Source§impl<'a> GlobalAlloc for Manager<'a>
Implementation of the standard library’s GlobalAlloc trait for any wrapped
type that implements Allocator_trait.
impl<'a> GlobalAlloc for Manager<'a>
Implementation of the standard library’s GlobalAlloc trait for any wrapped
type that implements Allocator_trait.
This implementation delegates the standard allocation operations to the wrapped allocator’s methods, converting between Rust’s and Xila’s allocation types.
§Safety
The implementation upholds the safety guarantees required by GlobalAlloc:
- Memory is properly aligned according to the layout
- Deallocation uses the same layout that was used for allocation
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout. Read more