Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!news.mathworks.com!newsfeed.internetmci.com!vixen.cso.uiuc.edu!sdd.hp.com!hp-pcd!hp-cv!reuter.cse.ogi.edu!qiclab.scn.rain.com!slc.com!servio!servio!aland
From: aland@servio.slc.com (Alan Darlington)
Subject: Re: OrderedCollection new:
Message-ID: <1995Dec27.213929.4035@slc.com>
Sender: news@slc.com (USENET News)
Nntp-Posting-Host: servio
Organization: GemStone Systems, Inc., Beaverton OR, USA
References: <4bk6t3$jii@pcnet2.pcnet.net> <4bqnj1$snc@ralph.vnet.net> <4brnm6$9ji@villa.fc.net>
Date: Wed, 27 Dec 1995 21:39:29 GMT
Lines: 53

"William D. Gooch" <goochb@rwi.com> writes:
<snip>
> I am BTW very surprised that IBM Smalltalk would give you a
> result from "new: 123" whose basicSize is zero.  Not having
> read the IBM Smalltalk docs, I can't say whether this is an
> incorrect result, but it doesn't seem right unless someone 
> has decided that basicSize in IBM Smalltalk should have quite
> a different contract from what it does in VisualWorks.
<snip>

I took a quick look at this problem, using VisualAge 3.0.
OrderedCollection uses an instance variable to keep track of
the "real" collection.  (This strategy avoids the "become:"
problem when growing or shrinking collections - "become:" was
very slow on VA 2.5, but is pretty decent in 3.0 (an order
of magnitude faster).)

Since the OC object never changes size, #basicSize (a primitive
instance method in class Object) always reports the same result.
However, when I evaluated

    (OrderedCollection new: 123) elements size

I got a result of 123, showing that the OC object has indeed
used the "hint" from the #new: message.  (Note that this is
just a performance issue, and that there is no requirement
for a particular Smalltalk implementation to make use of
such hints.  :-)

  Interestingly, while

    (OrderedCollection new: 0) elements size

gave a result of 0,

    OrderedCollection new elements size

gave a result of 8!  (Somebody at IBM is concerned with growing
performace - good job, guys!  :-)  Of course, if you deal with
a lot of very small collections and are concerned with your
memory footprint, this could be a :-( ...

  Anyone interested in more details should try

    (OrderedCollection new: 123) basicInspect

Their code is quite readable, too.

  Cheers,
  Alan
    (standard disclaimer)


