[vlc-devel] [PATCH] DVB-S scanning support

Rémi Denis-Courmont remi at remlab.net
Tue Aug 3 15:15:34 CEST 2010


On Tue, 3 Aug 2010 13:31:58 +0200, Rémi Duraffort <ivoire at videolan.org>
wrote:
>> It would be nice not to care about memory allocation. But I do not see
>> how that could work. Keep in mind another thread can always change the
>> variable's value asynchronously.
> Or we can add a var_Lock("my_var") to get a pointer to the const char
> without strdup (but that's really dangerous IMHO : too many bad-usages).

As long as we only reference variables by their name rather than by direct
pointers with reference count, this would require multiple look-up in the
variables tree. So this would most probably be slower than copying the
(typically short) strings. On top of that, we would still one line of code
to 'release' the string anyway (var_Unlock() instead of free()). And we
could not rely on free(NULL) working properly anymore, which is useful in
error paths especially. So there is really is no gain.

Also, we would need to replicated the variable API set with unlocked
functions. The variable lock cannot be recursive, because it is used with a
condition variable.

As a side note, I have been trying to convert the XML API to return const
char * values. It's not as simple as I thought. It's always the same issue:
you need to care how 'long' the string remains valid, which is a non issue
with strdup().

-- 
Rémi Denis-Courmont
http://www.remlab.net
http://fi.linkedin.com/in/remidenis




More information about the vlc-devel mailing list