Crate xalloc [] [src]

Dynamic suballocators for external memory (e.g., Vulkan device memory).

Provided Algorithms

Name Time Complexity Space Complexity
TLSF (Two-Level Segregated Fit) O(1) O(N)
Free space bitmap O(size) O(size)

(size: heap size measured by the number of allocation units, N: number of allocations)

Examples

use xalloc::{SysTlsf, SysTlsfRegion};
let mut tlsf = xalloc::SysTlsf::new(8u32);

// Allocate regions
let alloc1: (SysTlsfRegion, u32) = tlsf.alloc(4).unwrap();
let alloc2: (SysTlsfRegion, u32) = tlsf.alloc(4).unwrap();
let (region1, offset1) = alloc1;
let (region2, offset2) = alloc2;
println!("allocated #1: {:?}", (&region1, offset1));
println!("allocated #2: {:?}", (&region2, offset2));

// Deallocate a region
tlsf.dealloc(region1).unwrap();

// Now we can allocate again
tlsf.alloc(2).unwrap();
tlsf.alloc(2).unwrap();

Feature Flags

  • nightly — Enables optimizations which currently require a Nightly Rust compiler.

Reexports

pub extern crate num_traits;
pub extern crate num_integer;
pub use self::tlsf::Tlsf;
pub use self::tlsf::SafeTlsf;
pub use self::tlsf::SysTlsf;
pub use self::tlsf::TlsfBlock;
pub use self::tlsf::TlsfRegion;
pub use self::tlsf::SysTlsfRegion;
pub use self::tlsf::SafeTlsfRegion;
pub use self::bitmap::BitmapAlloc;
pub use self::bitmap::BitmapAllocRegion;

Modules

arena

Memory arena traits (used by Tlsf).

bitmap

Free space bitmap-based external memory allocator.

int

Traits for integral types.

tlsf

A dynamic external memory allocator based on the TLSF (Two-Level Segregated Fit) algorithm1.