• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java 3D Array (heap space problem)  RSS feed

 
Alireza Bahmanpour
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm trying to create a pixel representation of a room in 3d space, and for that I create a 3d array 'pixelArray[width][height][depth]', where width = 800, height = 700 and depth = 400.

When i try to run the porgram, it gives me the exception "java.lang.OutOfMemoryError: Java heap space".

Now before dealing with the exception, I wanted to see if my approach to creating such a big 3d array to represent a 3d room is a good practice or not. Is there a better way to solve my problem?

If it is the best way to approach this problem, how do I increase the heap space? I'm using eclipse as my IDE, and I tried changing the -Xms and -Xmx values to 512 in eclipse.ini, and also in the run configurations of my project, but they don't seem to be working since I still get the same error.

Thanks in advance
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Pedantic mode]There is no such thing as a 3D array, only an array of arrays of arrays[/Pedantic mode]

700 × 800 × 400 is 2.24 × 10^8, so over 0.2GB; if your pixels are ints, that is 4 bytes each, so you are looking at the best part of 900MB for that array. Can't think what to suggest, but it doesn't sound right to use so much memory. Can you think of an object-oriented approach with Wall objects and Door objects, etc?
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to use some other data-structure to decrease memory requirement.

Use VM arguments if you need to increase the memory
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We might be able to suggest a different data structure if you describe the problem you're trying to solve. I can point out, though, that most of the "pixels" (the word in 3D is actually "voxels") are just air, so there's no point in actually storing them. You need to use a structure that doesn't waste space storing the details of air.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!