Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is memory allocated in int array

Tags:

java

arrays

c#

oop

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[]{1,2,3,4};

Is memory allocation language specific ??

Thank you all

like image 360
Rohit Avatar asked Sep 27 '13 11:09

Rohit


1 Answers

Since you add a lot of language tags, I want to write for C#. In C#, this depends on operating system.

For 32-bit, each int is 4 byte and 4 byte also for reference to the object, that makes 4 * 4 + 4 = 20 byte

For 64-bit, each int is 4 byte and 8 byte also for reference to the object, that makes 4 * 4 + 8 = 24 byte

From C# 5.0 in a Nutshell in page 22;

Each reference to an object requires an extra four or eight bytes, depending on whether the .NET runtime is running on a 32- or 64-bit platform.

like image 57
Soner Gönül Avatar answered Oct 15 '22 02:10

Soner Gönül