[Gtk-sharp-list] Upcoming problems.
Mike Kestner
mkestner@speakeasy.net
27 May 2003 18:39:35 -0500
On Tue, 2003-05-27 at 17:58, Rachel Hestilow wrote:
> The problem is that, in theory, all the allocated strings we are getting
> from glib/gtk/etc are using g_malloc and g_free, but a correct JIT will
> use free() and thus could potentially be incompatible with g_malloc'ed
> results. Is that correct? If so, what needs to be done? Will wrapping
> the returned value in, say,
>
> char* gtksharp_realloc_string (char *str) {
> char *newstr = strdup (str);
> g_free (str);
> return newstr;
> }
I think the simplest way to deal with it is to treat the return like an
IntPtr in the DllImport, manually marshal it to a managed string with
PtrToStringAnsi in the method body, and then dispose the IntPtr returned
from the native method by pinvoking g_free. In other words, we take the
memory management out of the JIT's hands.
Or maybe I'm oversimplifying?
--
Mike Kestner <mkestner@speakeasy.net>