Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Swapping Page
    primarykey
    data
    text
    <p>I have built a custom hashmap using two arrays. One contains keys another values. Now, I see sometimes JVM can't able to allocate required memory for those arrays and throws exception. Is there any method to solve this using page swapping or any other method ?</p> <p>Code:</p> <pre><code>public class Test1{ public static void main(String args[]){ try { int arrays[] = new int[50000000] ; for ( int i = 0; i &lt; 50000000 ; i++) { arrays[i] = i ; } } catch(Exception e){ System.out.println(e) ; } } } </code></pre> <p>Edit:</p> <pre><code> public void load() { try { FileChannel channel2 = new RandomAccessFile(str1, "r").getChannel(); MappedByteBuffer mbb2 = channel2.map(FileChannel.MapMode.READ_ONLY, 0, channel2.size()); mbb2.order(ByteOrder.nativeOrder()); assert mbb2.remaining() == savenum * 8; for (int i = 0; i &lt; savenum; i++) { long l = mbb2.getLong(); keys[i] = l; } channel2.close(); FileChannel channel3 = new RandomAccessFile(str2, "r").getChannel(); MappedByteBuffer mbb3 = channel3.map(FileChannel.MapMode.READ_ONLY, 0, channel3.size()); mbb3.order(ByteOrder.nativeOrder()); assert mbb3.remaining() == savenum * 4; for (int i = 0; i &lt; savenum; i++) { int l1 = mbb3.getInt(); values[i] = l1; } channel3.close(); } catch (Exception e) { System.out.println(e); } } public void save() { try { FileChannel channel = new RandomAccessFile(str1, "rw").getChannel(); MappedByteBuffer mbb = channel.map(FileChannel.MapMode.READ_WRITE, 0, savenum * 8); mbb.order(ByteOrder.nativeOrder()); for (int i = 0; i &lt; savenum; i++) { mbb.putLong(keys[i]); } channel.close(); FileChannel channel1 = new RandomAccessFile(str2, "rw").getChannel(); MappedByteBuffer mbb1 = channel1.map(FileChannel.MapMode.READ_WRITE, 0, savenum * 4); mbb1.order(ByteOrder.nativeOrder()); for (int i = 0; i &lt; savenum; i++) { mbb1.putInt(values[i]); } channel1.close(); } catch (Exception e) { System.out.println("IOException : " + e); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    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