aspose file tools*
The moose likes Beginning Java and the fly likes how many objects is *too much? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how many objects is *too much?" Watch "how many objects is *too much?" New topic
Author

how many objects is *too much?

Michael Raymond Jr.
Ranch Hand

Joined: May 16, 2005
Posts: 178
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. ]

Scooby Snacks for everyone...<br /> <br />SCJA, SCJP 1.4
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
(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.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
 
Consider Paul's rocket mass heater.
 
subject: how many objects is *too much?