←back to thread

10 points zdw | 1 comments | | HN request time: 0s | source
Show context
Panzerschrek ◴[] No.45679301[source]
This approach for arena-allocated objects destruction seems for me to be a little bit unusual. Why not creating wrapper classes similar to unique_ptr o vector, which allocate memory from an arena instance and call destructors of stored objects upon their destruction?
replies(1): >>45680673 #
lieks ◴[] No.45680673[source]
Because the whole goal is to not need any sort of "pointer discipline". The way he does it, you can store as many pointers to the arena as you want without keeping track of them, as long as they don't survive the deallocation of the arena.

One example would be having a big graph inside the arena. Pointers to other elements can just be plain pointers.

With "conventional RAII" you need to know if your pointer is the only pointer left to know whether to call the destructor. That requires some sort of pointer tracking.

replies(2): >>45680983 #>>45683505 #
1. Panzerschrek ◴[] No.45680983[source]
Now I understand. The approach described in the article above allows shared semantics (not only unique owner like with unique_ptr and vector) with little overhead. But some overhead is still present - destructors are called via indirection and thus can't be inlined.