Does FileChannel#map allocate all the memory needed for the resulting ByteBuffer immediately, or is it only allocated on-demand during reads from the buffer?
I just tried mapping all of a 500+ MB file in a trivial test program, and looked at the memory usage of the process. (Using both Runtime#totalMemory and eyeballing it in the OS X Activity Monitor for a groovysh process.) The memory usage never passed 30-ish MB.
So, could a Java implementation “hide” some of its memory usage in native calls? And if so, is there a way to find out how much that is on OS X?
Memory usage is never straightforward. The actual buffer used by
FileChannel.mapis not part of the Java heap. Indeed the memory might be shared with other processes. The file may not even be read from the disc until the pages are touched.