[Mono-list] String Marshalling for P/Invoke

Michael Meeks michael@ximian.com
09 Jan 2003 10:25:58 +0000


Hi Marcus,

On Thu, 2003-01-09 at 03:42, Marcus wrote:
>  I've gotten conflicting answers over whether returning 
> malloc()'ed memory with g_free() is legal or not.

	It's theoretically illegal, since as you say allocators must be paired,
the g_malloc hook is there so people can put custom allocators in for
niche cases - memory debugging, wierd systems.

	In the overwhelming majority of real world cases g_free is a simple
'free' wrapper.

>  So far, I haven't observed 
> any specific problems, but as someone working on Qt#, which passes strings 
> back and forth a great deal, I'm concerned about the proper behavior.

	Hard to say what's best to do; short of using the native free / malloc
for everything [ loosing g_new0 etc. ]. I guess the current solution
works fine as long as no-one does funnies with the glib allocator [
which tends to break software en-masse anyway; people g_freeing
xmlAlloc-ated string, people xmlFree-ing, g_strdup'd strings etc. etc.
].

	It's prolly not a real problem,

	Regards,

		Michael.

-- 
 mmeeks@gnu.org  <><, Pseudo Engineer, itinerant idiot