For example, I have a std::map with known sizeof(A) and sizeof(B), while map has N entries inside. How would you estimate its memory usage? I\'d say it\'s something like
The formula is more like:
(sizeof(A) + sizeof(B) + factor) * N
where factor is the per entry overhead. C++ maps are typically implemented as red-black trees. These are binary trees, so there will be at least two pointers for the left/right nodes. There will also be some implementation stuff - probably a parent pointer and a "colour" indicator, so factor may be something like
(sizeof( RBNode *) * 3 + 1) / 2
However, all this is highly implementation dependent - to find out for sure you really need to examine the code for your own library implementation.