See memory usage in Visual C++
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
You can use the sizeof operator;
On my PC I get:
4 4 1
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) ?
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,
returns 4, the size of the int.
so
struct X {
Y *pointerY
};
will probably return the size of Y.
This,
class X{int i;};
returns 4, the size of the int.
so
struct X {
Y *pointerY
};
will probably return the size of Y.
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
Popular Topics
Advertisement