Memory usage of boost::unordered_multimap and boost::unordered_multimap
Hi, I need help in determining the amount of memory used by boost::unordered_multimap and boost::unordered_multimap. We have a large code base and we have some optimizations done using boost::unordered_multimap and boost::unordered_multimap. The speed it really good, but we want to measure the amount of space it is occupying. Can somebody please help with that? I would not be able to change to use a custom new/delete. Thanks
Can this be done by doing this,
unsigned n = mymap.bucket_count();
float m = mymap.max_load_factor();
if (m > 1.0) {
return (n * m) * (sizeof(value_type stored));
}
else {
return n * (sizeof(value_type stored));
}
to get an approimate size?
I got this idea from this question's answer -
https://stackoverflow.com/questions/25375202/how-to-measure-memory-usage-of-...
Thanks!
On Fri, Oct 6, 2017 at 3:46 PM, Ram
Hi,
I need help in determining the amount of memory used by boost::unordered_multimap and boost::unordered_multimap. We have a large code base and we have some optimizations done using boost::unordered_multimap and boost::unordered_multimap. The speed it really good, but we want to measure the amount of space it is occupying.
Can somebody please help with that?
I would not be able to change to use a custom new/delete.
Thanks
El 06/10/2017 a las 12:16, Ram via Boost-users escribió:
Hi,
I need help in determining the amount of memory used by boost::unordered_multimap and boost::unordered_multimap.
From a theoretical point of view, this might help: http://bannalia.blogspot.com/2013/10/implementation-of-c-unordered.html Joaquín M López Muñoz
Thanks Joaquin! That was very helpful! But I am trying to find out the size it occupies since we see a heap growth in our application. I want to rule out the possiblity of the growth being because of the unordered_map and the unordered_multimap. Can I use the method I mentioned in the previous mail? Or would a profiler help? An approximate number would do. Thanks!
On 6 October 2017 at 11:41, Joaquin M López Muñoz via Boost-users
El 06/10/2017 a las 12:16, Ram via Boost-users escribió:
Hi,
I need help in determining the amount of memory used by boost::unordered_multimap and boost::unordered_multimap.
From a theoretical point of view, this might help:
http://bannalia.blogspot.com/2013/10/implementation-of-c-unordered.html
The implementation has changed recently, C++17 requires that unordered_map and unordered_multimap use the same nodes, so now the unordered_multimap nodes are a little smaller, and a bit slower when there are a lot of elements with equivalent keys as it has to iterate through them one by one. I also now store the bucket index in nodes instead of the hash value. The container still allocates an array of (bucket_count + 1) buckets, and each node consists of the value, a std::size_t, and a pointer, and also whatever housekeeping is required for memory management. This can be quite costly compared to storing values in an array.
Thanks Daniel, our implementation is in C++11. So, did you mean that the code I had pointed out would give me the size? Thanks!
participants (3)
-
Daniel James
-
Joaquin M López Muñoz
-
Ram