What you are trying to obtain is not easy, I must say.

The static size might be solved by using sizeof, but the size of the allocated data will be more complicated (and less performant) to compute.

Suppose you have an unordered_map of string to integers.

    boost::unordere_map<string, int> my_map_;

The size int is known as sizeof(int), so it seems logical to multiply this value by the size of the container in order to get the actual size of the containers IN TERMS OF THE VALUE.

   size_t size_of_val = sizeof(int) * my_map_.size();

Now, what if the container does not contain integers, what if it contains a class? And what if that class uses dynamic allocation (std::string for example). You cannot know the size of each element in the container unless you visit them all!!

The reason above applies for the key elements, the key must be inside the container, but keys have dynamic data so they all have potentially different sizes!

So, my advice would be to:

1- Compute the static size of the unordered_map using size_of
2- Sum up the size of each element (key + value) in the map

Remarks: I don't know the internals of boost::unordered_map, if the class allocates data in the heap you are out of luck!

Best regards
Juan


On Mon, Nov 7, 2016 at 8:58 AM, Ram <sourceopen@gmail.com> wrote:
Hi,

Can anybody please help with this?

Thanks,
-R

On Mon, Nov 7, 2016 at 11:00 AM, Ram <sourceopen@gmail.com> wrote:
Hi,

I would like to calculate the size of my filled up boost::unordered_map including the house keeping. I was thinking of sizeof(boost:unordered_map mymap). I asked this question on stackoverflow but they say that wont help. Can  somebody tell me an easy way to find the size including the housekeeping that it takes?

The boost::unordered_map stores a std::string as the key and a pointer to my class object as the value.

Thanks,
Ram



_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users



--
Juan
:wq