How is memory allocated in int array

前端 未结 5 1722
南笙
南笙 2021-01-05 06:28

How much space does a int array take up? Or how much space (in bytes) does a int array consumes that looks something like this:

 int[] SampleArray=new int[         


        
5条回答
  •  無奈伤痛
    2021-01-05 07:00

    In Java int[] array is an Object which in memory represented by the header (8 bytes for x86) and int length field (4 bytes) followed by array of ints (arrayLength * 4).

       approxSize = 8 + 4 + 4 * arraylength 
    

    see more here http://www.javamex.com/tutorials/memory/object_memory_usage.shtml

提交回复
热议问题