Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
branches: ["trunk"]
pull_request:

jobs:
fmt:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup component add rustfmt
- run: cargo fmt --check

clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup component add clippy
- run: cargo clippy -- -D warnings

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: cargo test

msrv:
name: MSRV (1.31)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: "1.31"
- run: cargo +1.31 check
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "range-alloc"
version = "0.1.4"
version = "0.1.5"
description = "Generic range allocator"
homepage = "https://github.com/gfx-rs/range-alloc"
repository = "https://github.com/gfx-rs/range-alloc"
Expand All @@ -10,3 +10,4 @@ authors = ["the gfx-rs Developers"]
documentation = "https://docs.rs/range-alloc"
categories = ["memory-management"]
edition = "2018"
readme = "README.md"
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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

```rust
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

- Apache License, Version 2.0 ([LICENSE.APACHE](LICENSE.APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License ([LICENSE.MIT](LICENSE.MIT) or http://opensource.org/licenses/MIT)

at your option.
Loading