Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > huge bunch of objects

Reply
Thread Tools

huge bunch of objects

 
 
Katrin Tomanek
Guest
Posts: n/a
 
      06-17-2004
Hi again,

assume I have a java programm that will create about 500000 (half a
million !) objects (which are of a very easy type, just about 10
instance string-variables).

Do u think there will be a memory problem (on a "normal" pc with 256-512
MB RAM) or any other constraints or problems due to that big amount of
objects ?

thanx for your answers.

Katrin
 
Reply With Quote
 
 
 
 
Christophe Vanfleteren
Guest
Posts: n/a
 
      06-17-2004
Katrin Tomanek wrote:

> Hi again,
>
> assume I have a java programm that will create about 500000 (half a
> million !) objects (which are of a very easy type, just about 10
> instance string-variables).
>
> Do u think there will be a memory problem (on a "normal" pc with 256-512
> MB RAM) or any other constraints or problems due to that big amount of
> objects ?
>
> thanx for your answers.
>
> Katrin


You'll very likely have problems:

Let's do the calculations, assuming you're on a 32 bit platform.

Each object has an overhead of about 12 bytes:
<http://www-106.ibm.com/developerworks/ibm/library/i-garbage1/>

You have 500.000 custom Objects, that each have references to 10 String
objects, which hold a char array object. We'll also need to count the
reference to each object (32 bit)

So you need about (500.000 + (500.000 * 10) + (500.000 * 10)) * (12B + 4B) =
+-160MB for the Objects and their refs.

But you also need to keep the instance fields of the Strings themselves in
count:

3 ints and a char array (we've already counted the ref + the overhead of the
char array, now we need to count the contents of that char array. Let's
assume an average String length of 10 chars (a 16 bit primitive):

(10 * 4B) + 12B = 52B / String
5.000.000 * 52B = 247MB for the actual String data.

So you'll need a minimum of 160 + 247 = 407MB to hold all those objects in
memory at once.

This could be much less if many of the Strings were the same. The best case
scenario, in which you always reference the same, empty String, only takes
about 500.000 * (12B + 4B) + 500.000 * 40B = +- 26.7MB

--
Kind regards,
Christophe Vanfleteren
 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      06-18-2004
Katrin Tomanek wrote:
> Hi again,
>
> assume I have a java programm that will create about 500000 (half a
> million !) objects (which are of a very easy type, just about 10
> instance string-variables).


Don't do it Consider a design where you need less objects. Perhaps
your objects are to fine-grained? At least consider having a look at the
flyweight design pattern. It might be possible that you can externalize
the state (maybe even to a back end DB) of the objects to reduce your
memory consumption.

> Do u think there will be a memory problem (on a "normal" pc with 256-512
> MB RAM) or any other constraints or problems due to that big amount of
> objects ?


Why don't you just try? It should be trivial to create a test program
that instantiates 500000 objects in a loop, and adds them to a list or
array.

/Thomas
 
Reply With Quote
 
Andy Fish
Guest
Posts: n/a
 
      06-18-2004

>
> Don't do it
>


I would say, do it only if you really need to.

If you need very high speed access to these objects such that they must be
in RAM, and if you are going to deploy this app only on a system that is
dedicated to running that app.

After all, if it is a server and provides a valuable service to many users,
a few hundred bucks on extra RAM chips is no big deal.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory error due to the huge/huge input file size tejsupra@gmail.com Python 3 11-20-2008 07:21 PM
class objects, method objects, function objects 7stud Python 11 03-20-2007 06:05 PM
Re:YOU ARE A BUNCH OF CHILDREN!!! The Poster Formerly Known as Kline Sphere MCSE 3 01-12-2005 05:26 PM
trying to use <div> to hide a bunch of table rows David ASP .Net 4 05-21-2004 10:15 AM
Versioning, GAC, ASP.NET and a BUNCH of sites - Please Help! Nayt Grochowski ASP .Net 2 12-03-2003 12:03 AM



Advertisments