How can i estimate memory usage of std::map?

前端 未结 7 553
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 03:06

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

相关标签:
7条回答
  • 2020-11-29 04:08

    If you really want to know the runtime memory footprint, use a custom allocator and pass it in when creating the map. See Josuttis' book and this page of his (for a custom allocator).

    Maybe it's easier to ask for upper bound?

    The upper bound will depend on the exact implementation (e.g. the particular variant of balanced tree used). Maybe, you can tell us why you need this information so we can help better?

    0 讨论(0)
提交回复
热议问题