#memory-allocator #allocator #unstable #nightly #noop #no-std

nightly no-std noop-allocator

An Allocator that does nothing

2 releases

0.1.1 Sep 16, 2024
0.1.0 May 30, 2024

#389 in Memory management

Download history 1/week @ 2024-07-23 76/week @ 2024-09-10 114/week @ 2024-09-17 11/week @ 2024-09-24 6/week @ 2024-10-01

65 downloads per month

MIT/Apache

14KB
155 lines

noop_allocator

This crate provides an Allocator which does nothing: NoopAllocator<'_>.

Specifically:

  • allocate and allocate_zeroed will return Err for any non-zero-sized allocation requests
  • deallocate is a no-op, and does not require that ptr be "currently allocated", or fit layout.
  • shrink, grow, and grow_zeroed do not require that ptr be "currently allocated", or fit old_layout, and will successfully return the original pointer unchanged (with the length of the new layout) if the ptr is aligned for the new layout and the new layout is smaller or the same size as the old layout.

This type is usable as an Allocator when you want to borrow an existing memory range for use in a collection type, for example in Box or Vec.

Safety:

Many functions in this crate assume that impl Allocator for NoopAllocator<'_> as described above is sound, but feature(allocator_api) is unstable and the preconditions may change.

No runtime deps

Features