2个版本
0.9.3 | 2020年1月21日 |
---|---|
0.9.2 | 2020年1月14日 |
0.9.1 |
|
0.9.0 |
|
#568 in 内存管理
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);