-
Notifications
You must be signed in to change notification settings - Fork 120
Description
Hi,
With the 1.90.0 release, deque stores two copies of effectively the same allocator, just for two different value_types - T * and T:
container/include/boost/container/deque.hpp
Lines 716 to 718 in f818ee9
| struct members_holder | |
| : public ptr_alloc_t | |
| , public allocator_type |
Because of this, the size of the object increases, especially if the allocator is stateful, e.g. std::pmr::polymorphic_allocator.
Even with an empty allocator, it still increases the size for some ABIs, e.g. the Microsoft x86_64 ABI (MSVC and Clang). This is presumably due to different empty-base-optimization rules in different ABIs.
It should be possible to always store a single allocator, e.g. allocator_type, and copy-construct ptr_alloc_t from it only when needed. For any reasonable allocator (i.e. small and trivially copyable) this should be a zero-overhead operation for optimized builds.
sizeof results for reference:
Windows, x86_64, MSVC or Clang:
sizeof(boost::container::deque<int>) = 40
sizeof(boost::container::deque<int, std::allocator<int>>) = 40
sizeof(boost::container::deque<int, std::pmr::polymorphic_allocator<int>>) = 48
Linux, x86_64, GCC or Clang:
sizeof(boost::container::deque<int>) = 32
sizeof(boost::container::deque<int, std::allocator<int>>) = 32
sizeof(boost::container::deque<int, std::pmr::polymorphic_allocator<int>>) = 48