[Mono-devel-list] reading char * from extern function

A Rafael D Teixeira rafaelteixeirabr at hotmail.com
Fri May 23 21:53:02 EDT 2003


>From: Marcus <mathpup at mylinuxisp.com>
>
>When calling into existing libraries, it is not feasible to alter the 
>source
>code to change their memory-management policies.
>
>If I create "QObject* obj", then "name = obj->callName()" will return a 
>"const
>char*".  At this point, it is not permissible to call "free(name)".
>
> > Well, thats true. Functions should simply duplicate the string before
> > they return if needed. Else you have a memory leak which is impossible
> > to avoid.

In that case you have to write wrappers that copy the returned buffer to 
some memory that can be freed, either in C/C++ code using memory form malloc 
or in C# code using memory from the gc heap.

Happy developments,

Rafael Teixeira
Brazilian Polymath
Mono, MonoQLE Hacker

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail




More information about the Mono-devel-list mailing list