2 releases

0.9.3 Jan 21, 2020
0.9.2 Jan 14, 2020
0.9.1 Jan 14, 2020
0.9.0 Jan 14, 2020

#567 in Memory management

Download history 3/week @ 2023-11-20 9/week @ 2023-11-27 4/week @ 2023-12-04 15/week @ 2023-12-11 10/week @ 2024-02-19 9/week @ 2024-02-26 37/week @ 2024-03-04

56 downloads per month

MIT/Apache

9KB
126 lines

The boxing-arena crate provides a very simply reuse of Box allocation by keeping a vector of reusable Box allocations that can be used when wanting to wrap a value in Box.

It would be sometimes easier to introduce boxing-arena in code bases where Box is already used extensively than to use some other arena crate that affects type and life-time semantics more drastically.

Basic usage demonstration:

// Prepare a long-lived arena:
let mut ba = BoxingArena::new();

// ... per allocation ... :

// Instead of using `Box::new` directly, we do:
let boxed_big_value = ba.rebox(big_value);

// Instead of letting Rust drop and deallocate the Box, we do:
ba.unbox(boxed_big_value);

lib.rs:

The boxing-arena crate provides a very simply reuse of Box allocation by keeping a vector of reusable Box allocations that can be used when wanting to wrap a value in Box.

It would be sometimes easier to introduce boxing-arena in code bases where Box is already used extensively than to use some other arena crate that affects type and life-time semantics more drastically.

Basic usage demonstration:

use boxing_arena::BoxingArena;

// Prepare a long-lived arena:
let mut ba = BoxingArena::new();

// ... per allocation ... :
let big_value = [0u8; 0x1000];

// Instead of using `Box::new` directly, we do:
let boxed_big_value = ba.rebox(big_value);

// NOTE: Type of boxed_big_value is Box<[0u8; 0x1000]>

// Instead of letting Rust drop and deallocate the Box, we do:
ba.unbox(boxed_big_value);

No runtime deps