• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java 3D Array (heap space problem)

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Cob is sand, clay and sometimes straw. This tiny ad is made of cob:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic