More Speculations on Arenas in C++
6 hours ago
- #Object Lifetimes
- #Memory Management
- #C++
- Patrice Roy’s book 'C++ Memory Management' highlights stricter object lifetime rules in C++ compared to C.
- Common C memory management practices can be unsound in C++ due to lifetime semantics.
- C++20 introduced exceptions for `malloc` and similar functions to address lifetime issues.
- New C++ features like `start_lifetime_as`, `construct_at`, and placement `new` help manage object lifetimes.
- The article revisits an arena allocator implementation, correcting pointer provenance issues.
- Using array `new` in the arena allocator simplifies the code and avoids explicit casts.
- The arena allocator does not call destructors, which is allowed but may leak resources.
- Pointer provenance and lifetime considerations led to a cleaner allocator implementation.