asking question regarding string memory allocation in array
kumar abhay
Ranch Hand
Joined: Oct 02, 2001
Posts: 53
posted
0
i have a question regarding string memory allocation in array given below: int []arr=new int[6]; as in array each individual element(arr[0])will take 4 bytes n 4 for the referencing it to some memory.it means that the int array i just defined above will take 28 bytes rather than tking 24 bytes.i want to ask that a)why 4 bytes are preserved for referencing b)if int takes 4 bytes/element then how about long double, float n rest of other data types ,how much of data they will be saving. c)i want to ask that either 4 bytes are used for referencing for only int or referencing into the all data types would be varying due to the types. d)could you specify the differnt memory sizes used for different data types arrays i hope that sir you would reply this asap. take care thank you very much in advance with regards kumar abhay
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
Kumar Here si reference to the JLS section 4.2 that will answer your questions on the integer primitives and their sizes and range of values. Basically it is like this:
All but the char are signed. The char represents unicode characters in the range of 0 to 65535. As far as the sizes of the arrays and the size of the reference to each array I dont know that it is actually specified by the language itself and may be up to the implementation of the JVM you're using. If I'm wrong I know someone will correct me... hope that helps ------------------ Dave Sun Certified Programmer for the Java� 2 Platform [This message has been edited by Dave Vick (edited October 20, 2001).]
Dave
kumar abhay
Ranch Hand
Joined: Oct 02, 2001
Posts: 53
posted
0
thank u very much for ur reply but i act want to know the operation in array.i hope that u will help me for this take care with regards kumar abhay
Dave Vick
Ranch Hand
Joined: May 10, 2001
Posts: 3244
posted
0
Kumar I'm sorry I dont think I understand your question. What is it in the arrya you want to know? The array sizes and size of the reference to it? Let me know
------------------ Dave Sun Certified Programmer for the Java� 2 Platform
Marium Hasan
Greenhorn
Joined: Oct 03, 2001
Posts: 12
posted
0
Hello What I understand from your Query is: the Array is taking 28 bytes rather than 24 bytes is bec: Arrays in Java are objects & object variables always store refernces of the array & refernces are always stored with integral value. Therefore: int[] arr = new arr[6]; here, arr ---> references store as integer value --> 4 Bytes arr[0] --> 4 bytes arr[1] --> 4 bytes arr[2] --> 4 bytes arr[3] --> 4 bytes arr[4] --> 4 bytes arr[5] --> 4 bytes which equals to 28 bytes in total Infact, all reference variablei.e of objects will storewith the range of integer b) the "reference variable" of float & double or any other datatype will store with an integer. but the array values will have the same size as of datatype like: double arr[] = new double[6]; 48+ 4 = 52 bytes
I hope ypui have understood & will help in the next two questions Regards, Marium
kumar abhay
Ranch Hand
Joined: Oct 02, 2001
Posts: 53
posted
0
hi there, thank u very much miss marium for solving my problem.u mean to say that int array takes 4 bytes/element & float n double takes 8 bytes/element.i hope that your help will be there in the furure too. take care with regards kumar abhay
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: asking question regarding string memory allocation in array