Re: C Library: structured message proposal

Victor S. Abrash (victor@speech.sri.com)
Thu, 22 May 1997 19:09:34 -0700

Adam,

I think the structure approach would be great. Another advantage would
be fewer memory leaks.

>
> Potential problem: deallocation can get tricky. Since we now permit
> multiple pointers to the same space (instead of creating a new copy
> each time), the programmer has to be extremely careful not to deallocate
> the same space multiple times.
>

Put an extra field in the structure, ie,

struct Pobj {

... regular stuff ...

int validity;
}

The validity field can be set to a magic cookie when the structure is
valid, otherwise zero. When you deallocate an object, first set the
validity field to zero before freeing memory. Now any other pointers
will see that the memory they point to isn't a valid Pobj, and can
report an error. Note that you can also re-use the validity field to
indicate what type of object the structure holds.

Also, when you do
query = PRO_NewStruct("goal", PRO_NewList(l, a, v));
you should probably decide whether all objects are copied (in which case
you should free l, a, & v) or just pointed to (in which case it's an
error to free them). As long as it's consistent, we should be ok.

>
>
> What do you think? Will this be an improvement over the String-based
> approach? Are there better proposals?
>

This approach should make it easier to write robust programs. Without
some kind of change, OAA is just not robust enough for real use.

Victor