Re: DataInputStream
Robert Klemme wrote:
bob wrote:
The issue is that it's too slow.
How slow is that, and how fast should it be?
How much faster could it be, and what makes you think that's possible?
Ah, now we're getting closer to the point. I'd first test whether the
slowness is caused by the underlying stream or the reading procedure.
If it's the stream (e.g. because you read unbuffered from a socket)
then you might want to add buffering or you need a faster NIC. If
it's in the reading then look at Mark's suggestion.
The OS could also be a factor. So could other loads on the system, particu=
larly the I/O subsystem. Given that we don't know what speed is "too slow"=
and what speed is acceptable, nor the system configuration, nor the load p=
rofile, nor anything else, there's nothing we can say to affect the "too sl=
ow" evaluation.
What I'm hoping for is something like this:
byte[] b = new byte[nu=
mfloats*4];
Did you indent enough there?
dis.read(b, 0, numfloats=
*4);
b;
return f;
I don't know why, but it won't let me do the cast. Any ideas?
See Patricia's reply. Java works fundamentally different from C or C+
+. For example, there are no pointers into memory. I seriously
Well, there are, actually. In the case of the OP's code, they're 'b' and '=
f'. However, the pointers in Java are rigidly typed, unlike those in C, so=
you cannot cast a pointer to 'byte[]' into a pointer to 'float[]'.
suggest you make yourself familiar with the language and the JVM.
As another respondent suggested, NIO lets you alias typed 'ByteBuffer' inst=
ances as other types of 'Buffer'.
But this defeats the purpose of 'DataInputStream', which handles those mech=
anics for you under the hood, so why in the world reinvent the wheel? Just=
read your array of floats from the DIS.
Have you studied the Javadocs for the type?
<http://download.oracle.com/javase/7/docs/api/java/io/DataInputStream.html>
There are links from there to relevant ancillary documentation.
--
Lew