Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!news-xxxfer.readnews.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: DataInputStream Date: Wed, 5 Oct 2011 14:52:28 -0700 (PDT) Organization: http://groups.google.com Lines: 58 Message-ID: <20878450.465.1317851548409.JavaMail.geo-discussion-forums@prcs9> References: <1418dd7f-d5d1-4a2c-b77b-87666f6a9591@k15g2000yqd.googlegroups.com> <9f2a8cFh1nU1@mid.individual.net> <6cf66421-77a9-4088-b810-3bcc958cc8ca@i28g2000yqn.googlegroups.com> <2ec7550a-a3d9-40a9-bca1-e1fd2586429d@g33g2000yqc.googlegroups.com> <02b9b80f-ff02-499d-8f33-056080b114bb@s9g2000yql.googlegroups.com> <64b13101-4846-42d7-bc75-458eb326f73f@n8g2000yqd.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 2620:0:1000:437c:224:d7ff:fe69:5838 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1317851671 15181 127.0.0.1 (5 Oct 2011 21:54:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 5 Oct 2011 21:54:31 +0000 (UTC) In-Reply-To: <64b13101-4846-42d7-bc75-458eb326f73f@n8g2000yqd.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=2620:0:1000:437c:224:d7ff:fe69:5838; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:8581 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? =20 > 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: >> >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 byte[] b =3D new byte[nu= mfloats*4]; Did you indent enough there? >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dis.read(b, 0, numfloats= *4); >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 float[] f =3D (float[]) = b; >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return f; >> >> I don't know why, but it won't let me do the cast. =A0Any ideas? >=20 > 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. =20 Have you studied the Javadocs for the type? There are links from there to relevant ancillary documentation. --=20 Lew