[squeak-dev] Re: singleton?

nice ncellier at ifrance.com
Thu Apr 10 20:03:07 UTC 2008


Herbert König wrote:
> Hello Bernd,
> 
> 
>>> (World findA: PlotMorph) ifNil: [PlotMorph new openInWorld; yourself]
> BE> But i prefer the following because it does not depend on World and does
> BE> not need a "find" (my guess is that it takes longer the more morphs are
> BE> in the World):
> BE> class-side method:
> BE> theInstance
> BE> ^(self allInstances at: 1 ifAbsent: [self new].
> 
> my practical experience was just the opposite, I built a graph out of
> Morphs on the srceen. Unaware of the problem Bert mentioned I used
> GraphNode allInstances and GraphEdge allInstances.
> 
> It was quite slow in a bloated image. So I did World submorphs
> detect: ... which was *much* faster.
> 
> Morph>>findA: basically does this and iterating over a collection of
> only a small number is quite fast. (submorphs is just a collection.)
> 
> Whereas Behaviour>>allInstances has to dig through object after object
> if it finds one of the appropriate class.
> 
> Which means in the end *every* object in the image has been scanned.
> It doesn't help that this is done by primitives.
> 
> BTW PlotMorph allInstances will also give you all deleted but not
> yet garbageCollected instances too. This might prevent creating a new
> PlotMorph even if there is none left on the screen to display your
> plot.
> 
> Cheers,
> 
> Herbert                                        
> 
> 
> 

As you only need the first, someInstance could reduce the cost a little 
but would still be both inefficient and Project unfriendly.

Nicolas




More information about the Squeak-dev mailing list