Hello everyone.
I have a dispute with my friend about a random element access in array.
We have to variants:
1. We know address in memory of array start and offset of needed element, make a sum of this and you get an offset of element.
2. By subsequent access to all elements. For example we need a 5th element, we subsequently need to get a 1st, 2nd, 3rd and 4th elements.
I'm not sure what you are looking for, In Java you can access an array by using the reference to that array like this (assume you have a array of type int):
I think what the question means, is "how are arrays accessed by the computer's addressing?"
angel one
Greenhorn
Joined: Nov 16, 2009
Posts: 4
posted
0
Thank you for greeting, but i just lost my old account and this is why i made new.
The question was about realization of arrays in java.
As far as know in C arrays are addressed by start offset and number of element multiplied by size of datatype.
How this works in java?
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
4
posted
0
How do you plan to find out? the Java Language Specification didn't say much when I looked. What about the Java™ Tutorials? If that doesn't help, can you think of a way to try it out?
Yes, JLS leaves that up to the system implementaters, however typically elements of array occupy consecutive memory locations, and an array object contains additional length field.
angel one
Greenhorn
Joined: Nov 16, 2009
Posts: 4
posted
0
Thank you guys
But i lost the bet
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
4
posted
0
So what was your answer?
angel one
Greenhorn
Joined: Nov 16, 2009
Posts: 4
posted
0
Vijitha Kumara wrote:Yes, JLS leaves that up to the system implementaters, however typically elements of array occupy consecutive memory locations, and an array object contains additional length field.
Me and my friend, we both think that would be not efficient to use other implementation than specified by Vijitha.