Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to see memory layout of an object... 1

Status
Not open for further replies.

kimbly

Programmer
May 29, 2002
16
US
In order to understand what's really happening in memory when I create classes, add functions, have derived classes, etc., I would like to see the memory layout of my objects. I was told I could use breakpoints or output the memory, but I'm having trouble figuring out exactly what to do (and how to interpret that). As an example, say I have the following classes:

class A {
char a;
};

class B {
char b;
void b_func();
};

void main() {
A objectA;
B objectB;
}

I want to compare how "objectA" and "objectB" look in memory. Using Visual C++ 6.0, or some output functions, how can I see and interpret what is happening?

Your help is greatly appreciated, thank you!

Kim
 
stick objectA in watch1 and objectb in watch2. Then have a look at both of them side by side. You won't see an entry for b_func in the display.

Try the following:
Code:
class B
{
public:
   char b;
   virtual void b_func () {};
   virtual void c_func () {};
};

class C: public B
{
public:
   virtual void c_func () {};
};
You will get another entry called vtable. In the vtable, b_func will be the same in objectB and objectC but c_func will be different.
 
Thanks, that's exactly what I was looking for.

Kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top