Memory mapped files chew up huge amounts of virtual RAM and real RAM as well for the lookup tables and cached data, so they are not for routine use. They will mainly help random access especially when you have several threads accessing the same file. Don’t just assume they will improve performance. Further, they are limited by the address space. In a 32-bit JVM, you will be lucky if you can even handle a 1GB file window. Test both ways.
Direct buffers help primarily for bulk file operations, slewing through files doing little processing of the data or bulk copying. They are only for when you can allocate a mighty buffer at the start of the program and keep it till completion. Normal GC does not recover the unused direct buffers. Again, test both ways. Also be aware performance ratios will differ on different platforms.
Read and writing individual bytes goes through a lot of indirection, even though what you are trying to achieve is very simple. For Sun’s HotSpot you need to make sure that the method with your inner loop is very small. If it isn’t then the access code won’t be inlined and it will run very slowly.
![]() |
recommend book⇒Java NIO | |
| paperback | ||
|---|---|---|
| ISBN13: | 978-0-596-00288-6 | |
| publisher: | O’Reilly | |
| published: | 2002-08-15 | |
| by: | Ron Hitchens | |
| Covers NIO (new I/O) that arrived with JDK 1.4. | ||
| You can get the freshest copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) | |
| http://mindprod.com/jgloss/nio.html | J:\mindprod\jgloss\nio.html | |
![]() | ||
| Canadian Mind Products | ||
| mindprod.com IP:[65.110.21.43] | ||
| view Blog | Your face IP:[38.107.191.107] | |
| Feedback | You are visitor number 14,657. | |