Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could try using a RandomAccessFile object and use the setLength() method.</p> <p>Example:</p> <pre><code>File file = ... //Create a temporary file on the filesystem your trying to reserve. long bytes = ... //number of bytes you want to reserve. RandomAccessFile rf = null; try{ rf = new RandomAccessFile(file, "rw"); //rw stands for open in read/write mode. rf.setLength(bytes); //This will cause java to "reserve" memory for your application by inflating/truncating the file to the specific size. //Do whatever you want with the space here... }catch(IOException ex){ //Handle this... }finally{ if(rf != null){ try{ rf.close(); //Lets be nice and tidy here. }catch(IOException ioex){ //Handle this if you want... } } } </code></pre> <p>Note: The file must exist before you create the RandomAccessFile object.</p> <p>The RandomAccessFile object can then be used to read/write to the file. Make sure the target filesystem has enough free space. The space may not be "exclusive" per-say but you can always use File Locks to do that.</p> <p>P.S: If you end up realizing hard drives are slow and useless (or meant to use RAM from the start) you can use the ByteBuffer object from java.nio. The allocate() and allocateDirect() methods should be more than enough. The byte buffer will be allocated into RAM (and possible SwapFile) and will be exclusive to this java program. Random access can be done by changing the position of the buffer. Since these buffers use signed integers to reference position, max sizes are limited to 2^31 - 1.</p> <p>Read more on RandomAccessFile <a href="http://docs.oracle.com/javase/6/docs/api/java/io/RandomAccessFile.html" rel="noreferrer">here</a>.</p> <p>Read more on FileLock (the java object) <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileLock.html" rel="noreferrer">here</a>.</p> <p>Read more on ByteBuffer <a href="http://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html" rel="noreferrer">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload