6 releases

0.1.5 Feb 27, 2026
0.1.4 Jan 17, 2025
0.1.3 Feb 10, 2023
0.1.2 Jan 30, 2021
0.1.0 Dec 27, 2018

#51 in Memory management

Download history 61626/week @ 2025-12-28 80868/week @ 2026-01-04 85059/week @ 2026-01-11 96770/week @ 2026-01-18 106896/week @ 2026-01-25 114077/week @ 2026-02-01 113296/week @ 2026-02-08 107824/week @ 2026-02-15 111465/week @ 2026-02-22 249623/week @ 2026-03-01 164240/week @ 2026-03-08 161302/week @ 2026-03-15 166999/week @ 2026-03-22 168079/week @ 2026-03-29 156566/week @ 2026-04-05 188498/week @ 2026-04-12

699,706 downloads per month
Used in 1,825 crates (7 directly)

MIT/Apache

29KB
408 lines

range-alloc

A generic range allocator for Rust.

RangeAllocator<T> manages a contiguous range and hands out non-overlapping sub-ranges on request. It uses a best-fit strategy to reduce fragmentation and automatically merges adjacent free ranges on deallocation. Allocations can optionally be aligned to a given boundary without wasting the padding space.

Example

use range_alloc::RangeAllocator;

let mut alloc = RangeAllocator::new(0u64..1024);

// Basic allocation.
let a = alloc.allocate_range(256).unwrap();
assert_eq!(a, 0..256);

// Aligned allocation -- the returned range starts on a 128-byte boundary.
let b = alloc.allocate_range_aligned(64, 128).unwrap();
assert_eq!(b, 256..320);

// Free a range so it can be reused.
alloc.free_range(a);

// Grow the pool if you need more space.
alloc.grow_to(2048);

Minimum Supported Rust Version

The MSRV of this crate is at least 1.31, possibly earlier. It will only be bumped in a breaking release.

License

Licensed under either of

at your option.

No runtime deps