pub struct BumpAllocator { /* private fields */ }Expand description
The bump allocator used as the default rust heap when running programs.
Implementations§
Source§impl BumpAllocator
impl BumpAllocator
Sourcepub unsafe fn new(arena: &mut [u8]) -> Self
pub unsafe fn new(arena: &mut [u8]) -> Self
Creates the allocator tied to a provided slice. This will not initialize the provided memory, except for the first bytes where the pointer is stored.
§Safety
As long as BumpAllocator or any of its allocations are alive, writing into or deallocating the arena will cause UB.
Integer arithmetic in this global allocator implementation is safe when
operating on the prescribed HEAP_START_ADDRESS and HEAP_LENGTH. Any
other use may overflow and is thus unsupported and at one’s own risk.
Sourcepub const unsafe fn with_fixed_address_range(start: usize, len: usize) -> Self
pub const unsafe fn with_fixed_address_range(start: usize, len: usize) -> Self
Creates the allocator tied to specific range of addresses.
§Safety
This is unsafe in most situations, unless you are totally sure that the provided start address and length can be written to by the allocator, and that the memory will be usable for the lifespan of the allocator.
For Solana on-chain programs, a certain address range is reserved, so the allocator can be given those addresses.
Trait Implementations§
Source§impl GlobalAlloc for BumpAllocator
Integer arithmetic in this global allocator implementation is safe when
operating on the prescribed HEAP_START_ADDRESS and HEAP_LENGTH. Any
other use may overflow and is thus unsupported and at one’s own risk.
impl GlobalAlloc for BumpAllocator
Integer arithmetic in this global allocator implementation is safe when
operating on the prescribed HEAP_START_ADDRESS and HEAP_LENGTH. Any
other use may overflow and is thus unsupported and at one’s own risk.
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
layout. Read more