Crate realloc

Source
Expand description

A re-imagining of allocation in Rust from the ground-up. Fully no_std and portable.

Everything is built on top of the Allocator trait (and AllocatorExt); the goal is to make allocation itself 100% safe. To that end, it introduces the Alloc abstraction to ensure no allocation is double-freed or freed in the wrong allocator.

A secondary (but still very important) goal is genericity. For this, all built-in allocations are fully generic over what allocator they use, as well as the strategy used to handle allocation failures.

The feature flag global enables the global allocator framework, which allows one to set an allocator for all collections to use by default.

The crate comes with built-in system allocators for Linux (via aligned_alloc) and Windows (_aligned_malloc), but only with feature platform enabled. (with both global and platform, the global allocator is initially the platform allocator)

A number of containers are defined in the crate (at the time of writing, Box and Vec, to varying degrees of completeness). Note that Box is somewhat different to std::box::Box, due to the lack of compiler magic.

It also provides certain portable predefined allocators (currently Arena and Array). Of course, you can always define your own, and use them just the same.

Note that while the whole crate is no_std, and aside from platform is totally portable, it does make use of core::sync::atomic. If your desired platform doesn’t support atomics at all, this crate will not work.

Modules§

compat
Type aliases to ease the transition from std’s collections.
global
The framework for global allocators.
vec
A growable collection analagous to std::vec::Vec.

Macros§

strategy
Create a custom Strategy.

Structs§

Abort
A Strategy prescribing that the program immediately abort on failure.
Align
A type compactly storing a usize which is a power of two, and thus represents a possible alignment in the Rust abstract machine.
Alloc
An allocation returned from (and tied to) an Allocator.
Arena
An allocator that uses another allocator to obtain large blocks of memory, then hands those out in smaller chunks. Only once all chunks have been freed can the memory as a whole be freed.
Array
An allocator that hands out allocations from a statically-sized chunk of bytes.
Box
A pointer type that uniquely owns an allocation of type T.
Brand
A unique identifier for an Allocator.
Fallible
A Strategy prescribing that all fallible methods return Results.
Layout
Layout of a block of memory.
Optional
A Strategy prescribing that errors be discarded, and Options returned instead.
Panic
A Strategy prescribing that the program panic on failure.
PlatformAllocator
A “handle” for the platform’s allocator.
Static
A thread-safe const-compatible lazy initializing container, intended for creating allocators in static items.
Vec
A contiguous growable array type, written as Vec<T>, short for ‘vector’.

Enums§

Error
The comprehensive set of errors an allocator is allowed to return.

Traits§

Allocator
A type capable of providing and freeing arbitrary chunks of uninitialized memory on demand.
AllocatorExt
A collection of non-dyn-compatible helper methods for Allocator.
Strategy
A method for handling allocation failure.

Functions§

platform
Returns a reference to the platform allocator.