J
jeanlutrin
Hi all,
before anyone screams in anger at me and tell
me I should go back to some proper OO design
classes, I want to say that the following
scenario is completely hypothetical and my
question is one of curiosity (and desire to
understand better the working of the
language/JVM/you-name-it too)
Imagine that one hypotetical application is
using a huge long[] to represent an insane
number of "things" using a very efficient
bit encoded data structure. Say that
this long[] as a size of approx 100 Mb (!).
The "things" represented by this long[] wouldn't
be representable using Java object's because
of the memory footprint this would induce (on
the order of several Gb).
Now imagine that this long[] should be duplicated
(having the two long[] is not a problem and is
even mandatory: some different modifications will
be made on those two long[], then they'll be compared
- and "swapping" to disk is out of question due to
performance concerns).
For whatever reason, the second long[] should have
the size of the first one plus one element and all
the longs besides the last one should be the same
as in the first long[].
If there's enough memory available, what options are
there to achieve this?
I'm doing something like this (in my hypothetical simulation):
long[] sec = new long[first.length+1];
for (int i = 0; i < first.length; i++) {
sec = first;
}
sec[sec.length-1] = ...;
Would this be better (if only for the readability?) ?
long[] sec = new long[first.length+1];
System.arraycopy(first, 0, sec, 0, first.length)
sec[sec.length-1] = ...;
I also have another question, what if the memory gets
"fragmented" and there's enough memory available, but not
in a contiguous region.
Does the VM (or some VM) do some kind of "defragmentation" ?
Or some kind of pointer arithmetic ("splitting" the long[]
in pieces)?
Will the VM simply prevent the long[] from being created?
Are those behavior defined by some specs or are these
allowed to change?
Thanks in advance for any informations (I googled this
group's archives and found interesting thing, but I'm still
very curious about this),
Jean
before anyone screams in anger at me and tell
me I should go back to some proper OO design
classes, I want to say that the following
scenario is completely hypothetical and my
question is one of curiosity (and desire to
understand better the working of the
language/JVM/you-name-it too)
Imagine that one hypotetical application is
using a huge long[] to represent an insane
number of "things" using a very efficient
bit encoded data structure. Say that
this long[] as a size of approx 100 Mb (!).
The "things" represented by this long[] wouldn't
be representable using Java object's because
of the memory footprint this would induce (on
the order of several Gb).
Now imagine that this long[] should be duplicated
(having the two long[] is not a problem and is
even mandatory: some different modifications will
be made on those two long[], then they'll be compared
- and "swapping" to disk is out of question due to
performance concerns).
For whatever reason, the second long[] should have
the size of the first one plus one element and all
the longs besides the last one should be the same
as in the first long[].
If there's enough memory available, what options are
there to achieve this?
I'm doing something like this (in my hypothetical simulation):
long[] sec = new long[first.length+1];
for (int i = 0; i < first.length; i++) {
sec = first;
}
sec[sec.length-1] = ...;
Would this be better (if only for the readability?) ?
long[] sec = new long[first.length+1];
System.arraycopy(first, 0, sec, 0, first.length)
sec[sec.length-1] = ...;
I also have another question, what if the memory gets
"fragmented" and there's enough memory available, but not
in a contiguous region.
Does the VM (or some VM) do some kind of "defragmentation" ?
Or some kind of pointer arithmetic ("splitting" the long[]
in pieces)?
Will the VM simply prevent the long[] from being created?
Are those behavior defined by some specs or are these
allowed to change?
Thanks in advance for any informations (I googled this
group's archives and found interesting thing, but I'm still
very curious about this),
Jean