Skip to main content

Maximum Number of Elements per Array

1 reply [Last post]
chaose71
Offline
Joined: 2008-04-15

Hello there,

recently I stumbled over the problem of exceeding the maximum number of elements in an array. Currently I am finalizing a new open source software for segmenting & visualizing 3D (medical) volume data. When trying o allocated data for a volumetric data set of 1024x1024x2048 entries in a one dimensional int array, I got the error of trying to allocated a negative array size, as the number is obiousely a (signed) int and not a long.

I know a couple of workarounds for this, being either very technical or time expensive. So here are my questions:

a) Is there any chance that an upcoming java version will get bigger arrays? In times of 64 bit operating systems this might be necessary more often in close future.
b) Elsehow I would write the whole datastructure in C++ and use JNI to get it into the program ... does this sound like a good idea? I would like to avoid that since everything is done in pure Java so far.
c) Does anyone know a good alternative? Splitting the grid data into two halfes is not an option as I defenitely need to avoid the extra "if (upper_half)" in every voxel access.

ChaosE71

PS: Not sure if this is the right branch of the forum, but I'll give it a try! If not, please let me know where to post instead!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
peter__lawrey
Offline
Joined: 2005-11-01

> I know a couple of workarounds for this, being either
> very technical or time expensive. So here are my
> questions:
Why don't you use a multi-dimentional array. A two dimensional array would be fine. This is neither technical nor very time expensive. You can use a wrapper to hide the calculations meaning your code is not more complicated.

> a) Is there any chance that an upcoming java version
> will get bigger arrays? In times of 64 bit operating
> systems this might be necessary more often in close
> future.
It has been suggested many times, but is not planned for Java 7 AFAIF.
> b) Elsehow I would write the whole datastructure in
> C++ and use JNI to get it into the program ... does
> this sound like a good idea?
Its far more expensive than using a multi-dimensional array.

> I would like to avoid
> that since everything is done in pure Java so far.

If you really want to try it, use a direct allocated ByteBuffer which can contains any number of int, long or double values and uses JNI calls to obtain them, but is still pure Java.

> c) Does anyone know a good alternative? Splitting the
> grid data into two halfes is not an option as I
> defenitely need to avoid the extra "if (upper_half)"
> in every voxel access.
If you access pattern is purely random you have a performance issue right there. You should be thinking about how the CPU will cache the data for youa ccess pattern. If you have a cache efficient solution, these kinds of checks should be rare.

> PS: Not sure if this is the right branch of the
> forum, but I'll give it a try! If not, please let me
> know where to post instead!

IMHO The former sun java forums have a much wider audience, but this forum is fine.