2

I am not able to create 3D array with pixel value more then (100,100,3) in android. However it is working fine with array les then above mentioned dimension.

My code:

double mat[][][] = new double[400][400][3];
Error:java.lang.OutOfMemoryError: OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack available

However,

double mat[][][] = new double[100][100][3];

works fine. I am using emulated virtual machine to run android application.

Sulabh Tiwari
  • 307
  • 2
  • 6
  • 21

1 Answers1

3

It's probably memory. In Android double takes 64 bits, which are 8 bytes.

You are creating a 3D array 400x400x3 so the size will be

400 * 400 * 3 * 8 = 3.7MB

While the smaller size will be

100 * 100 * 3 * 8 = 234KB

It is more likely to get 234KB block of size rather than 3.7MB.


Tnx to Luca comment.

Community
  • 1
  • 1
Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216
  • you probably meant 64bit. which is 8 bytes. This number depends on the CPU architecture. the ARM architecture that most Android phones have, needs 64bits to represent a double. 400*400*3*8 = 3,66 MB – Luca S. Oct 20 '15 at 14:39
  • Plus a bit more for [array references](http://stackoverflow.com/questions/5839434/pointer-size-how-big-is-an-object-reference). – ci_ Oct 20 '15 at 14:56
  • Does that means, It is hard to deal with 3D array which takes memory more then above mentioned. What are the ways to deal such issues? Actually i am doing image processing using pictures, mostly i came across point where pixels will be in HD. – Sulabh Tiwari Oct 20 '15 at 17:54
  • Do you really need to use doubles as each component of a pixel? Usually images are using 8 bits for each component, which can be represented by a byte, so the required memory is 8 times less than what you use now. – hunyadym Oct 20 '15 at 21:35