scratchpad
A Rust library providing a stack-like dynamic memory pool with double-ended allocation support.
Features include:
- User-defined backing storage of data (static arrays, boxed slices, or mutable slice references).
- Allocation of any data type from any scratchpad instance.
- Double-ended allocation support (allocations from the "front" are separate from the "back", but share the same memory pool).
- Use of lifetimes to prevent dangling references to allocated data.
- Low runtime overhead.
- Support for
no_std
usage.
Usage
Add this to your Cargo.toml
:
[]
= "0.1"
and this to your crate root:
extern crate scratchpad;
Rust Version Support
The minimum supported Rust version is 1.25 due to use of the repr(align)
attribute.
no_std
Support
scratchpad
doesn't require the Rust standard library, although it makes use
of it by default (via the std
crate feature) to provide support for using
Box
as backing memory. For no_std
support, the std
feature must be
disabled in your Cargo.toml
:
[]
= { = "0.1", = false }
Box
support is still available for no_std
builds when using a nightly
toolchain by enabling the unstable
crate feature.
Unstable Features
The unstable
crate feature provides some additional functionality when using
a nightly toolchain:
ByteData
trait implementations foru128
/i128
.- Declaration of the function
Scratchpad::new()
asconst
, allowing it to be used directly to initialize static variables (lazy_static
crate or similar workaround needed otherwise). - Support for using
Box
as the storage type for allocations and marker tracking, regardless of whether thestd
feature is enabled (alloc
library is used ifstd
is disabled).
Simply add the unstable
feature to your Cargo.toml
dependency:
[]
= { = "0.1", = ["unstable"] }