<div dir="ltr"><br><br><div class="gmail_quote">2010/8/3 Rémi Denis-Courmont <span dir="ltr"><<a href="mailto:remi@remlab.net">remi@remlab.net</a>></span><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

On Tue, 3 Aug 2010 13:31:58 +0200, Rémi Duraffort <<a href="mailto:ivoire@videolan.org">ivoire@videolan.org</a>><br>
wrote:<br>
<div class="im">>> It would be nice not to care about memory allocation. But I do not see<br>
>> how that could work. Keep in mind another thread can always change the<br>
>> variable's value asynchronously.<br>
> Or we can add a var_Lock("my_var") to get a pointer to the const char<br>
> without strdup (but that's really dangerous IMHO : too many bad-usages).<br>
<br>
</div>As long as we only reference variables by their name rather than by direct<br>
pointers with reference count, this would require multiple look-up in the<br>
variables tree. So this would most probably be slower than copying the<br>
(typically short) strings. On top of that, we would still one line of code<br>
to 'release' the string anyway (var_Unlock() instead of free()). And we<br>
could not rely on free(NULL) working properly anymore, which is useful in<br>
error paths especially. So there is really is no gain.<br>
<br>
Also, we would need to replicated the variable API set with unlocked<br>
functions. The variable lock cannot be recursive, because it is used with a<br>
condition variable.<br>
<br>
As a side note, I have been trying to convert the XML API to return const<br>
char * values. It's not as simple as I thought. It's always the same issue:<br>
you need to care how 'long' the string remains valid, which is a non issue<br>
with strdup().<br></blockquote><div><br>Well it seems that strdup() makes sense actually. I've changed the code to reflect. :) <br></div></div><br clear="all"><br>-- <br><div dir="ltr"><font size="1"><a style="font-family: courier new,monospace;" href="http://blog.2of1.org" target="_blank">http://blog.2of1.org</a></font><br>
</div><br>
</div>