vk::mem::virtual_block · Structs · V1
5 public declarations with native signatures and source-owned contracts.
Stvk::mem::virtual_block::VirtualAllocation
Contract
Generation-checked identity in exactly one virtual block; no implicit free.
Stvk::mem::virtual_block::VirtualAllocationInfo
Contract
Placement snapshot; valid only while the matching allocation remains live.
Fields
user_data
user_data: usizeUninterpreted consumer metadata; no ownership or dereference is inferred.
offset
offset: u64size
size: u64Methods and associated items
set_user_data
Set user_data and return the updated record.
set_offset
Set offset and return the updated record.
set_size
Set size and return the updated record.
clone
fmt
eq
self and other values to be equal, and is used by ==.Stvk::mem::virtual_block::VirtualBlock
Contract
Virtual TLSF or linear allocator; owns host metadata and no native objects.
Mutations require exclusive access. Drop releases host metadata only. Callback construction borrows its allocation/free record through Drop; raw callback user data remains the unsafe constructor caller’s responsibility. This is not a Vulkan memory block or a pool with GPU lifetime tracking.
Methods and associated items
is_empty
Observe checked virtual emptiness in constant time.
set_user_data
Set opaque per-allocation metadata, with no native pointer dereference or ownership.
detailed_statistics
Calculate explicit virtual allocation/free-span extrema.
write_statistics_json
Stream virtual JSON diagnostics; no native memory is accessed.
new
new_with_algorithm
Create TLSF or linear host-only placement. No native storage is acquired.
use vk::{VirtualBlock, mem::{AllocationAlgorithm, PlacementStrategy}};
let mut block = VirtualBlock::new_with_algorithm(4096, AllocationAlgorithm::Linear)?;
let mut lower = block.allocate(64, 16, PlacementStrategy::Default)?;
let mut upper = block.allocate_upper(64, 16)?;
assert_eq!(block.allocation_info(&lower)?.offset, 0);
assert_eq!(block.allocation_info(&upper)?.offset, 4032);
block.free(&mut upper)?;
block.free(&mut lower)?;Errors
Rejects a zero size or failed host metadata reservation.
new_with_callbacks
Create host-only placement whose metadata uses borrowed Vulkan allocation callbacks.
TLSF/linear buffers, growth and detailed-JSON scratch storage use only this
allocation/free pair, with SystemAllocationScope::OBJECT. The block value
stays inline; tokens need no reference-count allocation. Reallocation and
driver internal-allocation notifications are not invoked. Drop releases
host metadata only; no Vulkan device or native memory is involved.
The callback record cannot expire while the block still owns storage:
let mut block;
{
let callbacks = vk::AllocationCallbacks::new();
// SAFETY: demonstration of record lifetime; null functions are rejected at runtime.
block = unsafe {
VirtualBlock::new_with_callbacks(1024, AllocationAlgorithm::Tlsf, &callbacks)
}.unwrap();
}
block.clear();Errors
Rejects zero size, a missing allocation/free function or failed host storage.
Safety
Callbacks must return uniquely owned memory of the requested size/alignment, or null on failure, and free only their own allocations. They must not unwind or reenter this block. Their code and user data must remain valid through block Drop and support calls from any thread, including concurrent independent blocks. Borrowing retains the callback record, not ownership of its raw user data.
allocate
Allocate an aligned region. Linear placement ignores the TLSF search strategy.
allocate_upper
Allocate downward in a linear block. Active ring mode rejects this request.
Errors
Rejects TLSF, invalid extents/alignment, exhausted space or host metadata.
free
Release a matching live identity. No native resource is destroyed or waited on.
allocation_info
Validate identity/generation and return the current offset/size snapshot.
clear
Invalidate all tokens and restore the full range, retaining host capacity. Users of previously returned offsets must stop using them before reuse.
statistics
Calculate detailed free-span statistics; this is not a constant-time hot path.
Stvk::mem::virtual_block::VirtualBlockDetails
Contract
Explicit virtual placement diagnostics; physical holes may not be immediately reusable by linear placement.
Fields
statistics
statistics: VirtualBlockStatsallocation_size_min
allocation_size_min: Option<u64>allocation_size_max
allocation_size_max: Option<u64>free_range_size_min
free_range_size_min: Option<u64>free_range_size_max
free_range_size_max: Option<u64>Methods and associated items
set_statistics
Set statistics and return the updated record.
set_allocation_size_min
Set allocation_size_min and return the updated record.
set_allocation_size_max
Set allocation_size_max and return the updated record.
set_free_range_size_min
Set free_range_size_min and return the updated record.
set_free_range_size_max
Set free_range_size_max and return the updated record.
clone
fmt
eq
self and other values to be equal, and is used by ==.Stvk::mem::virtual_block::VirtualBlockStats
Contract
Host metadata statistics. Alignment holes remain free, not reserved to a token. Linear free spans can include holes that placement cannot immediately reuse.
Fields
size
size: u64allocation_count
allocation_count: usizeallocated_bytes
allocated_bytes: u64free_bytes
free_bytes: u64free_region_count
free_region_count: usizelargest_free_region
largest_free_region: u64Methods and associated items
set_size
Set size and return the updated record.
set_allocation_count
Set allocation_count and return the updated record.
set_allocated_bytes
Set allocated_bytes and return the updated record.
set_free_bytes
Set free_bytes and return the updated record.
set_free_region_count
Set free_region_count and return the updated record.
set_largest_free_region
Set largest_free_region and return the updated record.
clone
fmt
eq
self and other values to be equal, and is used by ==.