C++ Class Object Memory Layout

18 Aug 2013

What is the memory layout of a C++ Class object?

It depends on the following factors:

For non-static data members, it is basically similar to C struct, the order in which you declare the data members of a class is the order they will be put/align in the memory.

This concept is important for debugging memory problems. The first and last data member are stored firstly and lastly in the memory space of a Class object, so they can be served as sentinels to protect the data integrity of a class. Check them often (in member functions) then you can get more clear picture of when data in a Class is being modified.

REFERENCE