#box #arena #allocations #allocation

boxing-arena

简单的Box分配复用

2个版本

0.9.3 2020年1月21日
0.9.2 2020年1月14日
0.9.1 2020年1月14日
0.9.0 2020年1月14日

#568 in 内存管理

MIT/Apache

9KB
126

boxing-arena crate通过维护一个可复用的Box分配向量,以简单地复用Box分配,在需要将值包裹在Box中时使用。

在一些已经广泛使用Box的代码库中引入boxing-arena可能比使用其他影响类型和生命周期语义更剧烈的 arena crate 更容易。

基本使用演示

// 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:

boxing-arena crate通过维护一个可复用的Box分配向量,以简单地复用Box分配,在需要将值包裹在Box中时使用。

在一些已经广泛使用Box的代码库中引入boxing-arena可能比使用其他影响类型和生命周期语义更剧烈的 arena crate 更容易。

基本使用演示

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);

无运行时依赖