F
fft1976
The JIT can't, but the coder can. If you want a vector of N
double-precision complex numbers in Java that is contiguous in memory,
for example, you could use a Java array of 2xN doubles and index into it
appropriately.
This is fanboy fantasy, not reality. If I have a library for dealing
with 3D vectors, I'm not going to lay out my data in flat arrays and
copy the vectors back and forth. Also, this trick won't work with non-
homogeneous records.
True. If you want a deep copy you will have to implement it yourself.
That's what I wrote. What was the point of your comment?
Or
you can make a deepCopy static utility method that exploits
"Serializable" to deep copy anything that's serializable simply by
serializing and deserializing it (which can use memory, or a temp file,
and not much memory if you make an auxiliary class implement both
InputStream and OutputStream, with its OutputStream methods writing to a
growable buffer and its InputStream methods consuming (possibly blocking
if necessary) from same. Closing the OutputStream aspect EOFs the
InputStream aspect. Then wrap in ObjectInput/OutputStream. You can use a
BlockingQueue of byte arrays of length 8192 (or whatever), serialize to
one end and deserialize from the other in concurrent threads, and it
will tend to not use much memory. Limit the BlockingQueue length to 1
item and it will never use much more than 8Kbyte (the OutputStream
aspect will block until the InputStream aspect consumes from the queue).
Ouch...
If the bulk of the time is spent performing arithmetic operations on
just a few values,
We are talking number crunching here, not useless pissing contests,
like calculating the digits of Pi.
If the arithmetic is bignum, the bulk of your time will be spent
performing individual bignum operations.
Contrary to what the term sounds like, number crunching is rarely
about bignums.
If the arithmetic is on smallnums in arrays and the computations are
mostly mutations, then you may want to use Java arrays,
That's what I said.
In practice,
Clojure access to Java arrays, even primitive arrays, seems to
be slow. This may be addressed in a future version.
Yeah, yeah...
I noticed that you decided to delete this, by the way:
In practice, experts seem to
agree that Clojure is 5-10 times slower than Java:
http://groups.google.com/group/clojure/msg/92b33476c0507478
(relevant follow-up set)