pub struct Allocator<LT: Lifetime> { /* private fields */ }Expand description
The general purpose memory allocator. Implemented as a segregated list allocator.
Implementations§
Source§impl<LT: Lifetime> Allocator<LT>
impl<LT: Lifetime> Allocator<LT>
Sourcepub unsafe fn new(
instance: &Instance,
physical_device: PhysicalDevice,
descriptor: &AllocatorDescriptor,
) -> Result<Self, AllocatorError>
pub unsafe fn new( instance: &Instance, physical_device: PhysicalDevice, descriptor: &AllocatorDescriptor, ) -> Result<Self, AllocatorError>
Creates a new allocator.
§Safety
Caller needs to make sure that the provided instance and device are in a valid state.
Sourcepub unsafe fn allocate_memory_for_buffer(
&self,
device: &Device,
buffer: Buffer,
location: MemoryLocation,
lifetime: LT,
) -> Result<Allocation<LT>, AllocatorError>
pub unsafe fn allocate_memory_for_buffer( &self, device: &Device, buffer: Buffer, location: MemoryLocation, lifetime: LT, ) -> Result<Allocation<LT>, AllocatorError>
Allocates memory for a buffer.
§Safety
Caller needs to make sure that the provided device and buffer are in a valid state.
Sourcepub unsafe fn allocate_memory_for_image(
&self,
device: &Device,
image: Image,
location: MemoryLocation,
lifetime: LT,
is_optimal: bool,
) -> Result<Allocation<LT>, AllocatorError>
pub unsafe fn allocate_memory_for_image( &self, device: &Device, image: Image, location: MemoryLocation, lifetime: LT, is_optimal: bool, ) -> Result<Allocation<LT>, AllocatorError>
Allocates memory for an image. is_optimal must be set true if the image is a optimal image (a regular texture).
§Safety
Caller needs to make sure that the provided device and image are in a valid state.
Sourcepub unsafe fn allocate(
&self,
device: &Device,
descriptor: &AllocationDescriptor<LT>,
) -> Result<Allocation<LT>, AllocatorError>
pub unsafe fn allocate( &self, device: &Device, descriptor: &AllocationDescriptor<LT>, ) -> Result<Allocation<LT>, AllocatorError>
Allocates memory on the allocator.
§Safety
Caller needs to make sure that the provided device is in a valid state.
Sourcepub unsafe fn deallocate(
&self,
device: &Device,
allocation: &Allocation<LT>,
) -> Result<(), AllocatorError>
pub unsafe fn deallocate( &self, device: &Device, allocation: &Allocation<LT>, ) -> Result<(), AllocatorError>
Frees the allocation.
§Safety
Caller needs to make sure that the allocation is not in use anymore and will not be used after being deallocated.
Sourcepub unsafe fn cleanup(&self, device: &Device)
pub unsafe fn cleanup(&self, device: &Device)
Releases all memory blocks back to the system. Should be called before drop.
§Safety
Caller needs to make sure that no allocations are used anymore and will not being used after calling this function.
Sourcepub fn allocation_count(&self) -> usize
pub fn allocation_count(&self) -> usize
Number of allocations.
Sourcepub fn unused_range_count(&self) -> usize
pub fn unused_range_count(&self) -> usize
Number of unused ranges between allocations.
Sourcepub fn used_bytes(&self) -> DeviceSize
pub fn used_bytes(&self) -> DeviceSize
Number of bytes used by the allocations.
Sourcepub fn unused_bytes(&self) -> DeviceSize
pub fn unused_bytes(&self) -> DeviceSize
Number of bytes used by the unused ranges between allocations.
Sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Number of allocated Vulkan memory blocks.