• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how many objects is *too much?

 
Michael Raymond Jr.
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i know i can use an arraylist, but for the sake of knowledge, on a standard 1gb of RAM computer, how many objects are too much?

for instance, i have File[] file1 = new File[20000];

I for sure need that much. Computer doens't crash or show signs of degradation when running programm, so 20k isn't 'too' much.

i'm just trying to get a feel for how many objects on X amount of memory is considered high. like, 1million object on 1gb ram, 10mill on 1tb ram, etc etc, not considering other environment variables like other processes running, etc.
[ November 21, 2007: Message edited by: Michael Raymond Jr. ]
 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(I think) as a language question, the array is only limited by the size of the int on the machine you're compiling on. 32 bit = 2^32

Most operating systems should allow you (at the cost of performance) to use much more RAM than is on your computer (See Operating Systems 101) via a virtual memory mechanism.

If you are going to have all these files open at once, there is usually an OS limitation on that as well. Older UN*Xes were in the ballpark of 1000 or 2000 open file limits. I don't really know about modern OSes.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most 32-bit Java virtual machines have a maximum upper limit on RAM usage of somewhat less than 2GB. The Java heap always has a fixed maximum size somewhere up to that value.

In Sun's implementation, each object uses up about 16 bytes plus the size of its instance variables. So say you have a class like

class Foo { int x; double y; }

every Foo you create will take up 28 bytes. Therefore in 1GB, you could create about 35 million of these. Of course, the JVM itself uses some, and an array to hold those 35 million objects would itself take up 140 MB (4 bytes per reference, times 35 million references!)

Anyway, hopefully this will give you an idea of how to think about this kind of thing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic