I have a structure of the following type
struct Node
{
int word;
int count;
unordered_map<Type, Node*> map;
}node;
Is it safe to assume that sizeof(node) gives you the correct size of that node in C++?
I am sure there will be padding in the structure but still will the sizeof take into consideration the correct size of the unordered_map.
yes, since
sizeofis usually calculated at compile time.That means that even if the hash size is 1000 or 100 or 10 or 1 or 0 you will get the same sizeof result.
don’t assume it will be enlarged even if the hash table will be modified.
however remember that sizeof in c++ can have awkward results sometimes (padding, place for the virutal table pointer, etc…)