Skip to content

boost::container::deque stores a redundant copy of the allocator, increasing size #328

@glebov-andrey

Description

@glebov-andrey

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions