[Bf-committers] Re: [Bf-blender-cvs] CVS commit: blender/source/blender/src header_info.c usiblender.c

Emil Brink emil at obsession.se
Tue May 30 15:00:47 CEST 2006


Ton Roosendaal wrote:
[BLI_dynstr]
> I would make a compatible system, so traditional strings and  
> 'dynstring' can be used both. Just by still using char pointers. That's  
> why I mentioned our malloc system, you can use that to find out if the  
> string is actually allocated, to prevent errors.
> 
> Further it'll fit in SNDA simply, you can then call standard string  
> library functions too, and all other string-eating stuff in Blender.

I see. That doesn't sound too difficult, if, as you say, it's possible
to ask the malloc system if a given pointer is indeed dynamic or not.

My dynstr module represents a string like this (comments edited to fit):

struct DynStr
{
  char	*str;
  size_t	len;	/*Length of string, in chars not including terminator.*/
  size_t	alloc;	/*Allocated bytes. Often more than len, for appending.*/
};

So, assuming that it's possible (through the malloc system) to get the
'allocated size' of a block of memory, there is no need to store that.
Then, if you can live with just using strlen() for the current length,
folding away the 'str' pointer shouldn't be a problem.

Of course it also requires that all operations on the dynamic string
always leave it as a properly terminated C string (which, incidentally,
mine do).

I guess that's something for Jiri to sink his teeth into, then. :)

Regards,

/Emil


More information about the Bf-committers mailing list