Anyone know CUP cache and java array?

K

Kevin

I think the CUP needs to load the data structure to its CPU cache in
order to operate them, right?
So when we have a java array, for example:

int[] myArray = new int[2000];

When I want to update one of its values, for example:

myArray[1000] = myArray[1000] + 1;

In order to process this line, will the CPU load the whole array into
its CPU cache to process? Or it can just load that particular item to
its cache to update it?

Thanks.
 
O

Oliver Wong

Kevin said:
I think the CUP needs to load the data structure to its CPU cache in
order to operate them, right?
So when we have a java array, for example:

int[] myArray = new int[2000];

When I want to update one of its values, for example:

myArray[1000] = myArray[1000] + 1;

In order to process this line, will the CPU load the whole array into
its CPU cache to process? Or it can just load that particular item to
its cache to update it?

Probably the latter. You can make arrays that, as a whole, are too big
to fit into cache.

- Oliver
 
E

Eric Sosman

Kevin wrote On 05/03/06 12:21,:
I think the CUP needs to load the data structure to its CPU cache in
order to operate them, right?

Usually, yes. Note that most modern computers have
multiple levels of cache with different characteristics.
Also, it may be possible to do some kinds of manipulation
(e.g., block copies) without involving some caches.
So when we have a java array, for example:

int[] myArray = new int[2000];

When I want to update one of its values, for example:

myArray[1000] = myArray[1000] + 1;

In order to process this line, will the CPU load the whole array into
its CPU cache to process? Or it can just load that particular item to
its cache to update it?

In one sense you don't know. You write this line of
Java, javac compiles it, and the JVM executes it ... somehow.
The details of the execution are (mercifully -- take my word
for it) hidden from you.

In another sense, it's easy to get at least a partial
answer. Choose whichever cache level interests you and
consider its size. Then write a Java program with an array
of, say, five times that size. Do you think your program
will run, or do you think the CPU cache will explode like
Mr. Creosote after the "waafer-thin" mint?
 
D

Dimitri Ognibene

The cpu, usually, doesn't know anything about arrays so it works only
on elements.
However the cpu or the memory interface can load a whole segment of
data near to the memory element you are accessing..but you can't have
any control on this behavior, which however is enough fast, it is
usefull for cicles on array..
Dimitri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top