Struct ccthw_ash_allocator::PageSuballocator
source · pub struct PageSuballocator { /* private fields */ }
Implementations§
source§impl PageSuballocator
impl PageSuballocator
sourcepub fn for_allocation(allocation: Allocation, page_size_in_bytes: u64) -> Self
pub fn for_allocation(allocation: Allocation, page_size_in_bytes: u64) -> Self
Create an allocator which takes memory from an existing allocation.
Params
- allocation: The allocation to use for suballocations.
- page_size_in_bytes: The size of each page in the allocation. The trade-off is that larger pages can waste memory for small allocations while small pages will increase allocation time.
Panic
Panics if allocation.size_in_bytes is not a multiple of page_size_in_bytes.
sourcepub fn release_allocation(self) -> Allocation
pub fn release_allocation(self) -> Allocation
Releases ownership of the underlying allocation.
Safety
Unsafe because:
- ownership is transferred, regardless of existing suballocations.
- the application must ensure that no suballocations are in-use after this call.
sourcepub unsafe fn allocate(
&mut self,
size_in_bytes: u64,
alignment: u64
) -> Result<Allocation, AllocatorError>
pub unsafe fn allocate( &mut self, size_in_bytes: u64, alignment: u64 ) -> Result<Allocation, AllocatorError>
Suballocate a region of memory.
Params
- size_in_bytes: the required size of the allocation.
- alignment: the required alignment of the allocation.
Safety
Unsafe because
- The caller must free the returned allocation
- The caller is responsible for synchronizing access (CPU and GPU) to the underlying memory
- The returned memory will always be aligned to the page size relative to the original allocation’s offset.
sourcepub unsafe fn free(&mut self, allocation: Allocation)
pub unsafe fn free(&mut self, allocation: Allocation)
Free a previously suballocated chunk of memory.
Safety
Unsafe because:
- The caller must not free the same allocation multiple times.
- The caller is responsible for synchronizing access to the underlying GPU memory.