The only thing a custom allocator can do in this case is to avoid some of the overhead used by the default allocator caused by alignment, if you know the final size and the overhead of std :: map due to internal pointers, you can reserve a buffer with necessary size and in the user allocator to use all this continuous memory.
The amount of memory that will be saved will depend on the types that you use on your card, and I donโt think it will.
As mentioned in the comments of รรถ Tiib and dau_sama, your best bet is boost :: flat_map, or you can just do it with
std::vector<std::pair<Key,Value>>
In any case, if you cannot change the third-party library, and it only accepts std :: map, you are still out of luck if it does not accept some type of iterator that you can adapt.
source share