by Scaevolus · 14y ago · 0 comments
long size = 0;
while (size >= 0) {
size += Files.map(veryBigFile).capacity();
}
You will see that VSIZE grows to be very big, but will decrease in size whenever the JVM runs the finalizers for the mmaped regions. Adding System.gc() to the loop makes the VSIZE stay constantly low on my machine, proving that at least my JVM (build 1.6.0_29-b11-402-11D50b on a mac) will unmap the underlying regions (JVM is allowed to ignore System.gc()).It's the Java equivalent of writing your own alloc().
It is very easy (and efficient) to implement java.io input and output streams backed by a buffer (as long as the buffer doesn't have to grow).
https://github.com/netty/netty/tree/bufferpooling https://github.com/netty/netty/issues/62 https://github.com/netty/netty/commit/c9968d6cbfa958f73a9868...