This is a port of Sebastian Aaltonen's OffsetAllocator package for C++ to 100% safe Rust. It's a fast, simple, hard real time allocator. This is espec

Search code, repositories, users, issues, pull requests...

submited by
Style Pass
2024-05-01 08:00:04

This is a port of Sebastian Aaltonen's OffsetAllocator package for C++ to 100% safe Rust. It's a fast, simple, hard real time allocator. This is especially useful for managing GPU resources, and the goal is to use it in Bevy.

The port has been made into more or less idiomatic Rust but is otherwise mostly line-for-line, preserving comments. That way, patches for the original OffsetAllocator should be readily transferable to this Rust port.

Please note that offset-allocator isn't a Rust allocator conforming to the GlobalAlloc trait. You can't use this crate as a drop-in replacement for the system allocator, jemalloc, wee_alloc, etc. A Rust allocator could be built out of this crate, but it doesn't come with one. This is by design, so that this allocator can be used to manage resources that aren't just CPU memory: in particular, you can manage allocations inside GPU buffers with it. By contrast, Rust allocators are hard-wired to the CPU and can't be used to manage GPU resources.

This allocator is completely agnostic to what it's allocating: it only knows about a contiguous block of memory of a specific size. That size need not be in bytes: this is especially useful when allocating inside a buffer of fixed-size structures. For example, if using this allocator to divide up a GPU index buffer object, one want to treat the units of allocation as 32-bit floats.

Leave a Comment