pub trait ByteAllocator {
// Required methods
fn alloc(&mut self, layout: Layout) -> AllocResult<NonNull<u8>>;
fn dealloc(&mut self, pos: NonNull<u8>, layout: Layout);
fn total_bytes(&self) -> usize;
fn used_bytes(&self) -> usize;
fn available_bytes(&self) -> usize;
}Expand description
Byte-granularity allocator for arbitrary-size allocations.
Provides methods for allocating and deallocating memory with byte-level granularity.
Required Methods§
Sourcefn alloc(&mut self, layout: Layout) -> AllocResult<NonNull<u8>>
fn alloc(&mut self, layout: Layout) -> AllocResult<NonNull<u8>>
Allocate memory with the given size (in bytes) and alignment.
§Arguments
layout- Memory layout specifying size and alignment requirements
§Returns
Returns a pointer to the allocated memory on success, or an error if allocation fails.
§Examples
let mut alloc = MyAllocator;
let layout = Layout::from_size_align(64, 8).unwrap();
let ptr = alloc.alloc(layout)?;Sourcefn total_bytes(&self) -> usize
fn total_bytes(&self) -> usize
Returns total memory size in bytes managed by this allocator.
Sourcefn used_bytes(&self) -> usize
fn used_bytes(&self) -> usize
Returns allocated memory size in bytes.
Sourcefn available_bytes(&self) -> usize
fn available_bytes(&self) -> usize
Returns available memory size in bytes.