[DGD]returning copy() of arrays, objects

Serhat Sakarya serhat at freud.et.tudelft.nl
Thu Feb 3 10:33:31 CET 2000


On Wed, 2 Feb 2000, Frantisek Fuka wrote:

> There is probably some rationale behind it but I don't understand why
> pointer values must be returned like this. And I probably don't need to
> understand it. But I need to know: Do I really have to return all
> objects, arrays and mapping like this? What could happen if I don't? (I
> tried and it seemed to work fine)

Well, as mentioned before it is often desirable to return arrays, etc by
value rather than by reference because you don't want the caller to be
able to alter the original contents by doing e.g.:

string *m;
m=SOME_SECURITY_DAEMON->query_admin();
m[0]="my_name";

So.. in any situation where you don't care especially if the original
contents *can* be altered you don't need to use anything like copy().
For your applications (areas, armour, weapons, etc) you probably don't
need to worry too much about this.

Regards,

Serhat Sakarya


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



More information about the DGD mailing list