Introduce FallbackSysArenaAllocator
Summary: It's difficult to use C++ allocators if they are not default-constructible. The non-default-constructibility "infects" the container, and any class that holds the container (transitively). In D21967640 (https://github.com/facebook/folly/commit/f0471228b89be4a399afcf0e9692c84754d06875), I made `folly::SysArenaAllocator` default constructible, and adopted the behavior of merely throwing `std::bad_alloc` in the event that we didn't *actually* initialize it with a `folly::SysArena`. In hindsight, it's not clear this was an improvement. All it did was move a compile-time problem to run-time. What I do here is a bit better. I enhance `CxxAllocatorAdaptor` such that it has two modes: - **Normal / classic mode:** non-default constructible. - Guaranteed at compile-time to have a non-null "inner allocator" - **`FallbackToStdAlloc` mode:** default-constructible. - Passes allocations through to `std::allocator` if no "inner allocator" provided Using this support, I introduce a new allocator, `folly::FallbackSysArenaAllocator`, which is similar to `SysArenaAllocator` *except* that it uses the fallback mode and is therefore default-constructible. This is useful in a large codebase where we want to use arena-allocation on a specific *instance* of a container type -- and not every single instance. Reviewed By: yfeldblum Differential Revision: D22938039 fbshipit-source-id: feaba12d76564a386a03e759eedf06a77bbc8942
Showing
Please register or sign in to comment