Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i fix: OutOfMemoryError with External Sorting
    primarykey
    data
    text
    <p>This program basically reads a huge amount of data from a binary file named data.bin where each item in the file is 1024 bytes long. the first 24 bytes of each item is the key and the remaining 1000 bytes just random information. and it adds all these items into an array list called "items" where it can then be sorted using a merge sort algorithm. </p> <p>but im getting an OutOfMemoryError on the line commented with ERROR after adding about 227475 items. This is all supposed to be externally sorted but its obviously not working right. so how could i split up the huge amount of items into smaller sets to be sorted then merged?</p> <pre><code> public static void main(String[] args) { System.out.println("Welcome to external merge sorter."); ArrayList&lt;Entry&lt;BigInteger, BigInteger&gt;&gt; items = new ArrayList&lt;Entry&lt;BigInteger, BigInteger&gt;&gt; (); TEntry&lt;BigInteger, BigInteger&gt; en = null; try { RandomAccessFile data = new RandomAccessFile("data.bin","rws"); System.out.println("Found file data.bin."); long length = data.length(); long recs = length / 1024; long count = 0; byte []b = new byte[1024]; System.out.println("Sorting..."); while(count &lt; recs) { count++; data.readFully(b); byte []key = Arrays.copyOfRange(b, 0, 24); byte []value = Arrays.copyOfRange(b, 24, 1024); System.out.println(count); //ERROR en = new TEntry&lt;BigInteger, BigInteger&gt;(new BigInteger(key), new BigInteger(value)); items.add(en); } } catch (Exception e) { e.printStackTrace(); } ItemCompare compare = new ItemCompare(); MergeSort sorter = new MergeSort(); sorter.sort(items, compare); System.out.println("Done!"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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