AllocationSizes

Struct AllocationSizes 

Source
pub struct AllocationSizes { /* private fields */ }
Expand description

The sizes of the memory blocks that the allocator will create.

Useful for tuning the allocator to your application’s needs. For example most games will be fine with the default values, but eg. an app might want to use smaller block sizes to reduce the amount of memory used.

Clamped between 4MB and 256MB, and rounds up to the nearest multiple of 4MB for alignment reasons.

Note that these limits only apply to shared memory blocks that can hold multiple allocations. If an allocation does not fit within the corresponding maximum block size, it will be placed in a dedicated memory block holding only this allocation, without limitations other than what the underlying hardware and driver are able to provide.

§Fixed or growable block size

This structure represents ranges of allowed sizes for shared memory blocks. By default, if the upper bounds are not extended using with_max_*_memblock_size, the allocator will be configured to use a fixed memory block size for shared allocations.

Otherwise, the allocator will pick a memory block size within the specifed range, depending on the number of existing allocations for the memory type.

As a rule of thumb, the allocator will start with the minimum block size and double the size with each new allocation, up to the specified maximum block size. This growth is tracked independently for each memory type. The block size also decreases when blocks are deallocated.

§Example

use gpu_allocator::AllocationSizes;
const MB: u64 = 1024 * 1024;
// This configuration uses fixed memory block sizes.
let fixed = AllocationSizes::new(256 * MB, 64 * MB);

// This configuration starts with 8MB memory blocks
// and grows the block size of a given memory type each
// time a new allocation is needed, up to a limit of
// 256MB for device memory and 64MB for host memory.
let growing = AllocationSizes::new(8 * MB, 8 * MB)
    .with_max_device_memblock_size(256 * MB)
    .with_max_host_memblock_size(64 * MB);

Implementations§

Source§

impl AllocationSizes

Source

pub fn new(device_memblock_size: u64, host_memblock_size: u64) -> Self

Sets the minimum device and host memory block sizes.

The maximum block sizes are initialized to the minimum sizes and can be increased using AllocationSizes::with_max_device_memblock_size and AllocationSizes::with_max_host_memblock_size.

Source

pub fn with_max_device_memblock_size(self, size: u64) -> Self

Sets the maximum device memblock size, in bytes.

Source

pub fn with_max_host_memblock_size(self, size: u64) -> Self

Sets the maximum host memblock size, in bytes.

Trait Implementations§

Source§

impl Clone for AllocationSizes

Source§

fn clone(&self) -> AllocationSizes

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AllocationSizes

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AllocationSizes

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Copy for AllocationSizes

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,