pub unsafe trait Allocator: Sized + Clone {
// Required methods
fn alloc(
&self,
size: usize,
alignment: usize,
allocation_scope: SystemAllocationScope,
) -> *mut ();
fn realloc(
&self,
original: *mut (),
size: usize,
alignment: usize,
allocation_scope: SystemAllocationScope,
) -> *mut ();
fn free(&self, memory: *mut ());
fn on_internal_alloc(
&self,
size: usize,
allocation_type: InternalAllocationType,
allocation_scope: SystemAllocationScope,
);
fn on_internal_free(
&self,
size: usize,
allocation_type: InternalAllocationType,
allocation_scope: SystemAllocationScope,
);
// Provided methods
extern "system" fn pfn_allocation(
user_data: *mut (),
size: usize,
alignment: usize,
allocation_scope: SystemAllocationScope,
) -> *mut () { ... }
extern "system" fn pfn_reallocation(
user_data: *mut (),
original: *mut (),
size: usize,
alignment: usize,
allocation_scope: SystemAllocationScope,
) -> *mut () { ... }
extern "system" fn pfn_free(user_data: *mut (), memory: *mut ()) { ... }
extern "system" fn pfn_internal_allocation(
user_data: *mut (),
size: usize,
allocation_type: InternalAllocationType,
allocation_scope: SystemAllocationScope,
) { ... }
extern "system" fn pfn_internal_free(
user_data: *mut (),
size: usize,
allocation_type: InternalAllocationType,
allocation_scope: SystemAllocationScope,
) { ... }
fn get_allocation_callbacks(&self) -> Option<AllocationCallbacks> { ... }
}Expand description
See https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#memory-allocation Cost-free allocator implementation for Vulkan Vulkan allows a custom memory allocator to be specified for host allocations Note that the vulkan implementation is not required to use this allocator (for example it might have to allocate memory with execute permissions), but you will at least receive the Allocator::on_internal_alloc and Allocator::on_internal_free notifications
§Safety
The implementations of alloc/realloc/free must satisfy an allocator behavior and the requirements of the specification If for some reason you choose the re-implement the pfn_* functions, they also need to follow the specification
Required Methods§
Sourcefn alloc(
&self,
size: usize,
alignment: usize,
allocation_scope: SystemAllocationScope,
) -> *mut ()
fn alloc( &self, size: usize, alignment: usize, allocation_scope: SystemAllocationScope, ) -> *mut ()
Sourcefn realloc(
&self,
original: *mut (),
size: usize,
alignment: usize,
allocation_scope: SystemAllocationScope,
) -> *mut ()
fn realloc( &self, original: *mut (), size: usize, alignment: usize, allocation_scope: SystemAllocationScope, ) -> *mut ()
Sourcefn on_internal_alloc(
&self,
size: usize,
allocation_type: InternalAllocationType,
allocation_scope: SystemAllocationScope,
)
fn on_internal_alloc( &self, size: usize, allocation_type: InternalAllocationType, allocation_scope: SystemAllocationScope, )
Sourcefn on_internal_free(
&self,
size: usize,
allocation_type: InternalAllocationType,
allocation_scope: SystemAllocationScope,
)
fn on_internal_free( &self, size: usize, allocation_type: InternalAllocationType, allocation_scope: SystemAllocationScope, )
Provided Methods§
extern "system" fn pfn_allocation( user_data: *mut (), size: usize, alignment: usize, allocation_scope: SystemAllocationScope, ) -> *mut ()
extern "system" fn pfn_reallocation( user_data: *mut (), original: *mut (), size: usize, alignment: usize, allocation_scope: SystemAllocationScope, ) -> *mut ()
extern "system" fn pfn_free(user_data: *mut (), memory: *mut ())
extern "system" fn pfn_internal_allocation( user_data: *mut (), size: usize, allocation_type: InternalAllocationType, allocation_scope: SystemAllocationScope, )
extern "system" fn pfn_internal_free( user_data: *mut (), size: usize, allocation_type: InternalAllocationType, allocation_scope: SystemAllocationScope, )
Sourcefn get_allocation_callbacks(&self) -> Option<AllocationCallbacks>
fn get_allocation_callbacks(&self) -> Option<AllocationCallbacks>
SAFETY: When re-implementing this function and using the provided pfn_* functions, you must ensure that the user_data value is a reference to self that lives as long as the allocation callback Moreover, as stated in https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkAllocationCallbacks.html pfn_internal_allocation and pfn_internal_free can only either be both None or be both Some
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.