Crates.io | scratchpad |
lib.rs | scratchpad |
version | 1.3.1 |
source | src |
created_at | 2018-04-28 02:11:38.21374 |
updated_at | 2021-02-19 10:05:16.077633 |
description | Stack-like memory allocator with double-ended allocation support |
homepage | https://github.com/okready/scratchpad |
repository | https://github.com/okready/scratchpad |
max_upload_size | |
id | 62700 |
size | 290,720 |
A Rust library providing a stack-like memory allocator with double-ended allocation support.
Note: scratchpad
is currently in maintenance mode. I've been considering
doing a major cleanup for some time to get rid of extraneous functionality and
reduce the surface area of unsafe
code, but there is currently no timeline
for this. I'll still apply fixes as needed, but development has otherwise
stalled.
Scratchpad
provides a method for quick and safe dynamic allocations of
arbitrary types without relying on the global heap (e.g. using Box
or
Vec
). Allocations are made from a fixed-size region of memory in a
stack-like fashion using two separate stacks (one for each end of the
allocation buffer) to allow different types of allocations with independent
lifecycles to be made from each end.
Such allocators are commonly used in game development, but are also useful in general for short-lived allocations or groups of allocations that share a common lifetime. While not quite as flexible as heap allocations, allocations from a stack allocator are usually much faster and are isolated from the rest of the heap, reducing memory fragmentation.
Features include:
no_std
usage.Add this to your Cargo.toml
:
[dependencies]
scratchpad = "1.3"
For Rust 2015 code, also add this to your crate root:
#[macro_use]
extern crate scratchpad;
The minimum supported Rust version is 1.25 due to use of NonNull<T>
and the
repr(align)
attribute.
no_std
Supportscratchpad
doesn't require the Rust standard library, although it makes use
of it by default (via the std
crate feature) to provide support for use of
Box
and Vec
in various places. For no_std
support, the std
feature
must be disabled in your Cargo.toml
:
[dependencies]
scratchpad = { version = "1.3", default-features = false }
Box
and Vec
support is still available for no_std
builds by enabling the
alloc
feature, which uses the alloc
crate directly:
[dependencies]
scratchpad = { version = "1.3", default-features = false, features = ["alloc"] }
The alloc
feature requires Rust 1.36.0 or later. Older versions of the
nightly toolchain can still use Box
and Vec
in no_std
code via the
unstable
feature.
The unstable
crate feature provides some additional functionality when using
a nightly toolchain:
Scratchpad::new()
as const
.Box
and Vec
support for no_std
code (enabled without the unstable
feature when using Rust 1.36.0 or later with the alloc
feature enabled).ByteData
trait implementations for u128
and i128
(enabled without
the unstable
feature when using Rust 1.26.0 or later).ByteData
trait implementation for all std::mem::MaybeUninit
types
wrapping other ByteData
types (enabled without the unstable
feature
when using Rust 1.36.0 or later).Simply add the unstable
feature to your Cargo.toml
dependency:
[dependencies]
scratchpad = { version = "1.3", features = ["unstable"] }
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.