As I continue to reflect on arenas and lifetimes in C++, I realized
that dealing with destructors is not so onerous. In fact, it does not even
impact my established arena usage! That is, implicit RAII-style
deallocation at scope termination, which works even in plain old C. With a
small change we can safely place resource-managing objects in arenas, such
as those owning file handles, sockets, threads, etc. (Though the ideal
remains [resource management avoidance][swr] when possible.) We can also
place traditional, memory-managing C++ objects in arenas, too. Their own
allocations won’t come from the arena — either because they lack the
interfaces to do so, or they’re simply ineffective at it (pmr) —
but they will reliably clean up after themselves. It’s all exception-safe,
too. In this article I’ll update my arena allocator with this new feature.
The change requires one additional arena pointer member, a bit of overhead
for objects with non-trivial destructors, and no impact for other objects.