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

Gonzalo Paniagua Javier gonzalo at ximian.com
Thu May 22 21:10:25 EDT 2003


El vie, 23 de 05 de 2003 a las 02:56, Marcus escribió:
> Having the runtime automatically free the C-string seems very dangerous.  Some 
> functions might return a pointer to a string but also store the pointer 
> elsewhere expecting that the string will remain allocated. Even worse, it's 
> possible for a function to return a pointer to a statically-allocated string. 
> (What happens in this case when the runtime tries to free the string?)

Yeah. Whoever uses that kind of functions should be aware of this issue
and try another options (IntPtr -> Marshal -> string and then free the
IntPtr?).

> 
> There is also a question about whether it is legal to mix malloc/free with the 
> glib equivalents. (Last I asked, I could not get a definite answer.)

It's legal for systems in which g_mem_is_system_malloc () returns TRUE.

-Gonzalo





More information about the Mono-devel-list mailing list