Module bounded

Module bounded 

Source
Expand description

A port of my bounded_alloc module from Monadic Bot. Unlike the original, this one is more tightly bound to the closures it is used with. Also unlike the original, this one does not rely on undefined behavior. By default, that is. There are two ways to make this bounded allocator useful:

  • Rely on std library UB and make alloc() unwind
  • Rely on a Nightly feature and set an unwinding alloc_error_hook

There is a secret CFG option for the first thing, and you can do the second thing yourself like:

#![feature(alloc_error_hook)]
use ::std::alloc::{Layout, set_alloc_error_hook};
fn your_alloc_error_hook(layout: Layout) {
   panic!("memory allocation of {} bytes failed", layout.size());
}
::std::alloc::set_alloc_error_hook(your_alloc_error_hook);

In either case, the with_max_alloc macro simplifies basic usage by performing the catch_unwind for you.

Macros§

with_max_alloc
Run a task with a statically known bound on allocation.

Structs§

Bounded
A Store wrapper which provides an allocation limit on top of whatever allocator it is given.