Crate outsource_heap

Source
Expand description

§outsource-heap

This library provides tools for outsourcing your heap allocations to various places, including:

  • A local file
  • A network drive
  • Anything which implements the Store trait, like a Vec<MaybeUninit<u8>>

Generally speaking, using this library is a bad idea. Once the Rust standard library has a stable allocator API this library will (hopefully) be made wholly obsolete.

In the meantime, let’s do some cursed nonsense.

§Getting Started

This crate provides a global allocator, which is used to intercept all allocations in your program so it can decide where to direct them. Therefore, the following must be placed somewhere in your project:

#[global_allocator]
static ALLOC: outsource_heap::Global = outsource_heap::Global::system();

Modules§

bounded
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:
file_backed
This module provides an example file backed allocator, which can be used with the scoped allocator methods provided by this crate. It is a simple wrapper for the linked_list_allocator crate.

Macros§

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

Structs§

Global
The top level GlobalAlloc implementor. Handles forwarding to various scoped allocators, and tracking what to deallocate each pointer with.

Traits§

Store
This trait is a shim for the GlobalAlloc trait, defined so that we can implement it for std defined types like Vec. See those docs for information on how to implement this trait correctly.

Functions§

run
Run a closure using a chosen global allocator. Threads spawned inside this closure will not use the assigned allocator.
run_async
Transform a Future to use a chosen global allocator. Threads spawned by this Future will not use the assigned allocator.
run_async_borrowed
Transform a Future to use a chosen global allocator, with a non 'static lifetime.
run_borrowed
Run a closure using a chosen global allocator, with a non 'static lifetime.