Memory usage of boost::unordered_multimap and boost::unordered_multimap

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory usage of boost::unordered_multimap and boost::unordered_multimap

Boost - Users mailing list
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

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory usage of boost::unordered_multimap and boost::unordered_multimap

Boost - Users mailing list
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-stdunordered-map
Thanks!

On Fri, Oct 6, 2017 at 3:46 PM, Ram <[hidden email]> wrote:
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


_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory usage of boost::unordered_multimap and boost::unordered_multimap

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
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
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory usage of boost::unordered_multimap and boost::unordered_multimap

Boost - Users mailing list
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! 

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory usage of boost::unordered_multimap and boost::unordered_multimap

Boost - Users mailing list
In reply to this post by Boost - Users mailing list
On 6 October 2017 at 11:41, Joaquin M López Muñoz via Boost-users
<[hidden email]> wrote:

> 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.
_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory usage of boost::unordered_multimap and boost::unordered_multimap

Boost - Users mailing list
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!

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users