Design of typed arena

I am trying to understand how the design of typed arena works: typed_arena - Rust

pub struct Arena<T> {
    chunks: RefCell<ChunkList<T>>,

struct ChunkList<T> {
    current: Vec<T>,
    rest: Vec<Vec<T>>,

Is the key idea here as follows:

  1. If we stored a RefCell<Vec<T>> , then when the Vec resizes, old references become invalid.

  2. Instead, we keep a Vec<T> and a Vec<Vec<T>> where:

when we hit the capacity of current: Vec<T>, instead of resizing current (and making refs invalid), we push current to rest, and allocate a new current: Vec<T>

Is this the key design decision of typed-arena? Is there any other idea I am missing ? [ want to make sure I understand what is going on before switching over ]

Yes, that is how it avoids invalidating pointers, which is a requirement for any arena allocator, since the main characteristic is that nothing is dropped or moved until the the arena itself is dropped.

The thing you may be missing is that this particular type of arena allocator is homogeneous -- everything is the same type -- as opposed to something like bumpalo that is heterogeneous.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.