macro_rules! static_allocator {
($size:expr) => { ... };
}
Expand description
Creates a static LinearAllocator
with the given
amount of bytes of backing memory.
Note that this creates an allocator backed by a static byte array, i.e. the memory isn’t dynamically allocated nor freed, it’s just a big static variable, one for each call of this macro. Generally this’ll appear once per crate if needed, there shouldn’t be much of a reason to have multiple of these, if any.
As such, even though this can be assigned to a variable (e.g. let arena = static_allocator!(1);
), that variable will only be a borrow of the single
static variable that this macro expands to. If such a function is called
multiple times, arena
will get a reference to the same arena every time.
§Example
use engine::allocators::{LinearAllocator, static_allocator};
static PERSISTENT_ARENA: &LinearAllocator = static_allocator!(1024 * 1024);