[DGD]Sharing variables between cloned objects.

Erwin Harte harte at xs4all.nl
Thu May 3 09:21:34 CEST 2001


On Thu, May 03, 2001 at 02:15:44AM -0500, Thomas Annandale wrote:
>   I am looking for a way for two objects of the same type to share a
> variable, so even if I clone two separate instances of them, the data in
> the variable stays the same between all of the instances and is not
> needlessly reproduced.  I know that in Java, you do this by declaring the
> variable as "static", but this doesn't seem to work in dgd.

Indeed, static global variables in DGD are normal global variables for
all intents and purposes, except in how they interact with the
save_object() and restore_object() kfuns.

> 
>   Specifically, I want a mapping that is initialized with data once and
> then left alone for the rest of its life.  A cloneable object will use
> this mapping frequently.  I don't want every clone to have its own copy of
> the mapping, as that seems like a big memory waste.  The only way I can
> think to do this now is to make a separate object to store the mapping 
> that all of the clones query whenever they need it.  Is there a better
> way?

Not that I can think of.  Of course you could go for the 'one object
per clonable' approach or make a generic object that stores all the
various bits for all clonables out there, whichever you find more
amusing, I guess. :-)

Erwin.
-- 
Erwin Harte
harte at xs4all.nl

List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list