[DGD]Setting global variables from create()

Felix A. Croes felix at dworkin.nl
Sun Jun 11 13:46:56 CEST 2000


"James Gaunt" <jamesgaunt at hotmail.com> wrote:

> Hi, I'm quite new to LPC coding so please have patience if this is a stupid 
> question...
>
> If I have an object with a global variable (for example a string 
> representing its long description) and I set it from the create() function 
> i.e.
>
> string desc;
>
> void create()
> {
>    desc="This is quite a long description";
> }
>
> Then is the long description stored twice in memory, once in the compiled 
> code of the object, and once in the global variable in the master object 
> (obviously with additional copies in any clones).

The string will be shared in memory when the object is created, but saved
to separate copies in swap space.  I therefore assume that you're really
worried about the amount of swap space taken up by this string, rather
than the amount of memory.


> My concern is that if I create a lot of objects (for example rooms with 
> large descriptions) which aren't cloned at all (in which case I wouldn't be 
> too worried) then all the descriptions are stored twice, taking up valuable 
> memory.
>
> If this is the case does anyone have any suggestions for getting around it, 
> or is it just a fact of life?

If you want to use the absolute minimum of swap space for these strings,
you can set the description from an external object which you destruct
thereafter, by adding the following function to the rooms:

    void set_desc(string str)
    {
	desc = str;
    }

Regards,
Dworkin

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



More information about the DGD mailing list