Array bounds checks
Cedric Berger
cedric@wireless-networks.com
Thu Oct 26 12:41:00 GMT 2000
"Boehm, Hans" wrote:
>
> > Currently we can't implement that because our array header is attached
> > directly to the data. We'd have to add an indirection to make
> > contiguous multidimensional arrays work.
> >
> I don't think I understand the problem. You would allocate the same objects
> as now, except all in one contiguous chunk. I.e. you'd get something like
>
> Main array header (includes a "contiguous" tag)
> Main array (containing pointers to subarrays)
> 0th subarray header
> 0th subarray
> 1st subarray header
> ...
>
> It should still be possible to locate the [i,j] element with a
> multiplication and a couple of additions. There are some slightly
> unfortunate GC implications, but you could easily make this optional. Even
> if you make the decision at run-time, the main cost is dead code.
>
I'm wrong in saying that even if the multiarray has been initially
allocated rectangular, that fact can be changed later, i.e.:
double[][] array = new double[10][10];
later...
array[2] = new double[20];
Which poses some slight problem with this approach...
Cedric
More information about the Java
mailing list