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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jan 3, 2012, 6:24 AM EST
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.
Chintan RathodRank #516 · 4.8K reputationPosted Jan 3, 2012, 6:25 AM EST
So as you can see size of int and char is 4 and 2 respectively, size of class is 6 bytes.
Thank You.
Akshay TeotiaRank #603 · 4K reputationPosted Jan 3, 2012, 10:20 AM EST
VulpesRank #55 · 29.2K reputationPosted Jan 3, 2012, 10:34 AM EST