Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!newsfeed.pitt.edu!gatech!newsfeed.internetmci.com!uwm.edu!reuter.cse.ogi.edu!qiclab.scn.rain.com!slc.com!servio!servio!aland
From: aland@servio.slc.com (Alan Darlington)
Subject: Re: VW Object "weight"
Message-ID: <1996Feb20.210640.5637@slc.com>
Sender: news@slc.com (USENET News)
Nntp-Posting-Host: servio
Organization: GemStone Systems, Inc., Beaverton OR, USA
References: <4fvgig$sj9@maverick.tad.eds.com>
Date: Tue, 20 Feb 1996 21:06:40 GMT
Lines: 35

"Robert J. Sullivan" <rjs@atl.ema.ema.com> writes:
> In an attempt to compute the amount of storage objects are taking up I implemented the following 
> methods (adapted from the AT classes):
<snip> 
> 
> I am wondering how accurate this might be.  If the weight of referenced objects is included in the 
> total weight will the weight be overstated if several objects have common references?  How many times 
> should the weight of nil be counted since there is only one nil in the entire system.  Then there is 
> the question of the weight of the object reference itself versus the object it refers to.  Some sage 
> counsel would be appreciated.

Your totals will usually be too high.  Depending on your application, they
may be off by orders of magnitude!

When I did this, I used a global dictionary to keep track of objects which
have already contributed their size.  If an object is in the dictionary,
it answers zero as its size; otherwise it answers its true size and adds
itself to the dictionary.  This produces an accurate single total size
(which is usually what you want), but the sizes of individual objects may
not be at all accurate, depending on the order of evaluation.

Another problem I ran into is that in a large system, the performance of
the dictionary becomes a problem, since you get a large number of hash
collisions.  As I remember, I used a double level identity dictionary, with
the outer level being accessed by the class of the object, and the inner one
accessed by the object itself.  I also had problems with arrays, which in
Smalltalk V/286 hashed by size!  (We had lots of small arrays.)  I had to
override (very temporarily, of course!) the hash method for Array to get
better performance.

  Hope this helps,
  Alan
    (standard disclaimer)


