3

I have a pretty large double array of say 1,71,00,000 elements. I need to traverse through the array, slice the array in smaller arrays of 10k points each and the remaining points(if any) into the last slice.

I have a basic code:

public static boolean getSliceOfArray(double[] arr,int slice_len)
    {
        //arr: big array
        //slice_len: 10,000
        System.out.println(arr.length);
        int n_times=(arr.length/slice_len);
        int i=0;
        for(int n=0;n<n_times;n++)
        {
            Arrays.copyOfRange(arr,i,i+slice_len);
            i=i+slice_len;

        }
        System.out.println(n_times);

        if(i!=arr.length)
        {
            System.out.println( Arrays.copyOfRange(arr,i,arr.length).length);

        }

        return true;
    }

It gives me following output:

I/System.out: 17100000
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 13.428ms
    Starting a blocking GC Alloc
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 36.867ms
I/xample.styleap: Starting a blocking GC Alloc
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 26.012ms
    Starting a blocking GC Alloc
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 32.625ms
    Starting a blocking GC Alloc
I/xample.styleap: Waiting for a blocking GC Alloc
I/xample.styleap: WaitForGcToComplete blocked Alloc on HeapTrim for 21.645ms
    Starting a blocking GC Alloc
I/System.out: 1710

When I do the same with considerably smaller sized array the output is not like this. Why does it show "Waiting for a blocking GC Alloc" and these messages? Is it a serious issue? JVM issue or my logic error?

Sayan Sen
  • 795
  • 1
  • 7
  • 18

1 Answers1

3

Using android:largeHeap="true"in my manifest.xml solved this issue.

Sayan Sen
  • 795
  • 1
  • 7
  • 18