Size of class

Hi all, i coded a class and was interested to check its size in terms of bytes.

class Node
{
public:
Node();
~Node();
char getContent();
void setContent(char input);
bool wordFound();
void setWordIndicator();
Node* findChild(char input);
void appendChild(Node* child);
std::vector<Node*> childrenVector();

private:
char content;
bool wordMarker;
std::vector<Node*> children;
};

I used the sizeof-function to get the size but it returns as 20bytes. I am sure that char and bool are 1 bytes each. The private-member children shows as 16 bytes which got me curious.

I understand there could be padding but could anyone provide a breakdown as to how 16 bytes come about?
You're using the default padding, which aligns variables on a boundary.

A char is defined to be 1 byte. But althought a bool represents 1 bit, it isn't necessarily represented as 1 byte, it can be represented by an int. It wasn't introduced to save space, it as introduced to allow overloading on a logical value, rather than a numeric value.
The private-member children shows as 16 bytes which got me curious.
I understand there could be padding but could anyone provide a breakdown as to how 16 bytes come about?

It is implementation-defined.
Depending on the compiler/platform I just tried, I saw sizes of 12, 16, 24, 32 bytes for the children (with the size of Node, respectively, 16, 20, 32, 40 bytes)

To learn about the details of what's stored in the object representation of the vector you're using, you'd have to examine your library code or load the program in the debugger. Typically, there are three pointers (start, size, and capacity) and the allocator (at least as of c++11).
Hi, Cubbi and kbw. Thank you for sharing with me those information. Appreciate it =)
Topic archived. No new replies allowed.