Better memory mapped buffers

Because of the way java/jni treats memory mapped files i had to come with a better way of rendering/stream my pointclouds efficiently. The java memory mapped buffers are not cleared. Even not when setting the buffers to null. the only way to free memory was to explicitly call System.gc() which is a severe penalty. so i’ve written a small c++ program that will let the user create a file map then map a portion of this file and finally return a bytebuffer.

this is my innermost streaming loop
int handle = DTStreamFiles.createFile(
sceneGraphDir + node.getDataFile(),
DTStreamFiles.GENERIC_READ,
DTStreamFiles.FILE_SHARE_READ,
DTStreamFiles.OPEN_EXIST,
DTStreamFiles.FILE_ATTRIBUTE_NORMAL);

			if (handle != -1) 
			{
				int byteLength = node.wantedPoints*MathConstants.VERTEX_SIZE;
				int mapHandle = DTStreamFiles.createFileMapping(handle,
						DTStreamFiles.PAGE_READONLY, 0, 0);
				
				if (mapHandle != 0) 
				{

					int valPointer = DTStreamFiles.mapViewOfFile(
							mapHandle,
							DTStreamFiles.FILE_MAP_READ, 
							0, 
							0, 
							byteLength);

					if (valPointer != 0) 
					{
						ByteBuffer buf = DTStreamFiles.getDirectBuffer(valPointer, byteLength);

//DO WHAT U WANT WITH THIS BUFFER it isn’t valid anymore after unmapping the file

//unmap view of file
					DTStreamFiles.unMapViewOfFile(valPointer);
					//close mapping handle
					DTStreamFiles.closeHandle(mapHandle);	
				}
				//close handle
				DTStreamFiles.closeHandle(handle);

it can be found here :
http://home.hccnet.nl/pj.holverda/better_file_mapping.rar