[DGD]Sharing variables between cloned objects.

John West McKenna john at ucc.gu.uwa.edu.au
Thu May 3 11:15:27 CEST 2001


Thomas Annandale writes:

>  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?

I've been doing more Lua coding than LPC lately, so I might be confused.
A variable of type "mapping" isn't the mapping itself - it's just a
reference to it.  You can have multiple variables referring to the same
mapping.

I'd expect the easiest way to do this is have a separate object that
creates and fills the mapping, and also has a function to return a
reference to it.  Your objects can then query this when they are created,
and store it in their own private variables.

That way you don't have many copies of the data, and you don't have the
overhead of the query call every time you want to use it.

If you really don't want an extra object, you could have the blueprint for
the clonable object create the mapping, and have the clones query it for
their references.  But that's rather ugly.

John

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



More information about the DGD mailing list