fstring distinguished type

Martin Pool mbp at samba.org
Tue Jan 15 18:36:07 GMT 2002


On 15 Jan 2002, John Malmberg <wb8tyw at qsl.net> wrote:
> How about passing arrays by a descriptor?
> 
> typedef struct {
>     int tag;              /* Code to type of data. helps debug */
>     int class;            /* Memory allocation */
>     size_t allocation;    /* Maximum size of string */
>     size_t currentsize;   /* Current used allocation */
>     char * pointer;       /* Pointer to string data */
> } string_dsc;

This is very similar to GString

  http://developer.gnome.org/doc/API/2.0/glib/glib-strings.html

I suspect GNOME does more complicated string manipulations than Samba,
so they need growable strings more than we do.

I suppose it's been reinvented or reproduced many times.

This also has the problem that every existing part of the code that
assumes a pstring is equivalent to a char* will have to be converted.
Also, the conversion will have to be done in one go, whereas with the
union the two types were binary-compatible and so conversion could be
done one source file at a time.

This type only allows errors to be detected at runtime, but if we are
going to use pre-allocated buffers it is more desirable to do the
checking at compile time.

Simply checking for dynamic overflow can be done using dmalloc,
mcheck(), ElectricFence, Insure++, etc.

> The class is used to determine how the data was allocated.  So that the 
> routine knows if the string is dynamically allocated or static.  It can 
> also indicate what pool the allication came from, and if it is permitted 
> to reallocate the string to fit.

I think if you're going to take the performace/complexity hit of using
this structure you might as well just dynamically allocate everything.

-- 
Martin 




More information about the samba-technical mailing list