I would like to implemented a custom allocator for node-based containers like std::unordered_map
or std::list
. For that allocator I need to specify the size of the nodes. How do I get this? I know in C++17 at least std::unordered_map
has a node_type
, but I'm currently bound to C++11
How to determine node size of std containers?
Asked Answered
© 2022 - 2024 — McMap. All rights reserved.
using Map = std::unordered_map<uint64_t, uint64_t>
I getsizeof(Map::value_type) == 16
, but the allocator is actually called to allocate 24 bytes for one entry – Goodkinstd::list<uint64_t, Allocator<uint64_t>>
the allocator instance created isAllocator<std::_List_node<uint64_t>>
). – Morguetypename std::allocator_traits<Allocator>::rebind_alloc<Node>
to allocate internal objects (nodes) of typeNode
. – Wekslerstd::unordered_map
, so it is impractical to hardcode something. – Goodkinsizeof(value_type) + sizeof(void*)*4
works. – Goodkin