See memory usage in Visual C++

Started by
4 comments, last by dietepiet 15 years, 3 months ago
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
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
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) ?
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.
It'll be atleast the size of a pointer for the platform you are on.
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.

This topic is closed to new replies.

Advertisement