Hi friends
I have a class which have 2 variable one char and one integer in this case how much memory a class can have.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 3, 2012, 3:34 PM
Akshay TeotiaPosted Jan 3, 2012, 3:20 PM
Chintan RathodPosted Jan 3, 2012, 11:25 AM
So as you can see size of int and char is 4 and 2 respectively, size of class is 6 bytes.
Thank You.
VulpesPosted Jan 3, 2012, 11:24 AM
However, on a 32 bit system, each object of a class requires 8 bytes of overhead and on a 64 bit system the overhead is 16 bytes.
So, the total heap memory needed will be at least 14 bytes (32 bit system) or 22 bytes (64 bit system).
Also, to improve processor efficiency, the fields of an object may not be laid out contiguously. Any 'unused' bytes between fields will therefore further increase the memory needed for the object.