|
-
September 26th, 2008, 02:46 AM
#1
How to print total memory allocated for an object
Hi,
class Sample
{
int x, *ptr;
public:
Sample()
{
ptr = new int[100];
}
~Sample()
{
}
};
int main()
{
cout << "SizeofClass" << sizeof(Sample); //gives me output 8
Sample sm;
cout<< "SizeofObject" << sizeof(sm); //also gives me output 8
}
But i assume the size of sample object should be 4(x) + 400(ptr) = 404 bytes
Is there anyway that i can know or print the total memory alloacted which
x + ptr = 4 +400 = 404 bytes
Is my assumption correct ? Pls clarify me on this
Thanks
Kiran
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|