Jump to content
  • Advertisement
Sign in to follow this  
edwin2026

See memory usage in Visual C++

This topic is 3624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Could somebody tell me how to see the profile for each data member of the class /methods which we made how many kb/mb it consume system memory in Visual C++? Thanks

Share this post


Link to post
Share on other sites
Advertisement
You can use the sizeof operator;


int i;
class X
{
};
std::cout << sizeof(int) << " " << sizeof(i) << " " << sizeof(X) << std::endl;



On my PC I get:

4 4 1

Share this post


Link to post
Share on other sites
How about like this?

struct X {
Y *pointerY
}

struct Y {
Z *pointerZ
}

what does the sizeof(X) return?
Is it the sizeof(y)*sizeof(z) ?

Share this post


Link to post
Share on other sites
Well, on my pc (using VC++2008) an empty class's size is 1

This,

class X
{
int i;
};


returns 4, the size of the int.

so
struct X {
Y *pointerY
};

will probably return the size of Y.

Share this post


Link to post
Share on other sites
Quote:
Original post by edwin2026
How about like this?

struct X {
Y *pointerY
}

struct Y {
Z *pointerZ
}

what does the sizeof(X) return?
Is it the sizeof(y)*sizeof(z) ?


How should VC++ know whether *pointerZ is pointing to valid data or is uninitialized? Therefore, sizeof(X) will just give the size of the struct Y itself, not the size of the data it might point to. In this case, sizeof(X) will probably be 4, one single pointer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!