Why the overhead when allocating objects/arrays in Java?

Posted by Gnijuohz on Programmers See other posts from Programmers or by Gnijuohz
Published on 2012-08-28T03:15:59Z Indexed on 2012/08/28 9:50 UTC
Read the original article Hit count: 251

Filed under:
|

How many bytes an array occupies in Java? Assume It's a 64bit machine and also assume there are N elements in an array, so all these elements would take up 2*N, 4*N or 8*N bytes for different types of array.

And a lecture in Coursera says that it would occupy 2*N+24, 4*N+24 or 8*N+24 bytes for a N element array and the 24 bytes is called overhead, but didn't explain why the overhead is needed.

Also objects have overheads, which is 16 bytes.

What exactly are these overheads? What are these 24/16 bytes composed of?

Also, do these overheads only exist in Java? How about C, C++ and Python?

© Programmers or respective owner

Related posts about java

Related posts about memory