• 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

Can you calculate the size of an array?

 
Ranch Hand
Posts: 287
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm just curious but can you get the space used by an array of BufferedImage? I'm currently using:
Everything works fine but I was thinking of doubling the size of the array to provide more granularity of the sky images but then started wondering how much space (KB) this might take up. Is there a simple way of finding out?
 
Bartender
Posts: 5478
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are 800x600 = 480.000 pixels, one pixel taking up 4 bytes, so that will be about 2 MB per BufferedImage. So an array of 26 of them will take about 52 MB.
 
Mich Robinson
Ranch Hand
Posts: 287
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent, thank you.

Am I right to worry about the amount of space being used or do modern PC's and laptops have so much space now that it's not worth caring. I don't notice any slow down in my game from doubling the size but I just worry that someone with an even older PC than mine might start having issues.
 
Piet Souris
Bartender
Posts: 5478
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think you should be worried about that. As you say, nowadays pc's have plenty of memory. But you could have a look at the Runtime-class, it has some useful methods to query available memory.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic