Both Trie
and Trie2
end up taking 216 bytes because of how memory alignment works. Even though Trie2
has an extra char
variable, the compiler adds padding after it to make sure the array of pointers (child[26]
) starts at an 8-byte boundary (which is required for pointers on a 64-bit system). This padding makes the total size of both classes the same, even though the structure of the two classes is slightly different.