|What ByteBuffer is Not||Sequentially Reading A File|
|How It Works||Little Endian Files|
// how to simulate a ByteBuffer.toArray ByteBuffer bb; ... byte contentsOnly = Arrays.copyOf( bb.array(), bb.position() );
If you don’t want to allocate large hunks of your virtual address space, you could allocate a smaller MappedByteBuffer at some offset in the file other than 0, and read a decently large chunk of it. When done, allocate a new MappedByteBuffer. You can be considerably more generous in your chunk size than when allocating buffers.
Alternatively, you could do your I/O in a more conventional way using FileChannel. read( ByteBuffer dst ), to read the next chunk of the file into a pre-allocated ByteBuffer. This approach is clumbsier than traditional stream I/O, but can be more efficient, especially when you slew over most of the data, or access it via the backing array. It will pay off if for example you were processing just a 4-byte field in a 512-byte record, since only the bytes you need are copied from the buffer, not the entire record.
The effect is even more pronounced with MappedBuffers and large records where pages of records you don’t need are not even read into RAM (Random Access Memory).
available on the web at:
optional Replicator mirror
Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : . If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Your face IP:[184.108.40.206]
|Feedback||You are visitor number 64,266.|