开发者

Size in bytes of a structure containing unordered_map

开发者 https://www.devze.com 2023-04-06 21:16 出处:网络
Need to find the exact size in bytes, occupied by a tree data structure that I have implemented. Node Structure is as follows

Need to find the exact size in bytes, occupied by a tree data structure that I have implemented. Node Structure is as follows

struct Node
{
    int  word;       
    int   count;       
    unordered_map<int, Node*> map;       

}node;   

What I have been doing is size(int)*2(for word and count) + map.bucket_count() * (sizeof(int) + sizeof(Node*)) and repeatedly do this for each node. Is this the correct way of doing this if i am neglecting the element overhead of storage in the unordered_map?

Also, if I am correct map.bucket_count() gives the number of buckets that are currently allocated that is including the pre- allocated ones. Should I be using map.size() instead which will ignore the pre-allocated buckets?

Or instead of all this, is it better to use tools like MemTrack to find th开发者_C百科e memory used?


Or instead of all this, is it better to use tools like MemTrack to find the memory used?

Yes. There's no telling from the outside how much memory an unordered_map or other complex, opaque object takes, and a good memory profiler might also show you how much overhead the memory allocator itself takes.

0

精彩评论

暂无评论...
验证码 换一张
取 消