Module arena

Module arena 

Source
Expand description

Arena allocator for protobuf message data.

The Arena provides fast bump allocation for protobuf messages and their contents (strings, bytes, repeated fields, sub-messages). All allocations are freed together when the arena is dropped.

§Example

use protocrap::arena::Arena;
use allocator_api2::alloc::Global;

let mut arena = Arena::new(&Global);

// Allocate raw memory
let ptr: *mut u64 = arena.alloc();
unsafe { *ptr = 42; }

// Or place a value directly
let value = arena.place(String::from("hello"));
assert_eq!(value, "hello");

// All memory freed when arena drops

§Custom Allocators

The arena accepts any &dyn Allocator, allowing custom memory placement:

let mut arena = Arena::new(&my_custom_allocator);

Since the arena batches small allocations into large blocks, the overhead of dynamic dispatch on the allocator is negligible.

Structs§

Arena
Arena allocator for protobuf message data.