How to free heap allocated my malloc?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it there a way in C# to free heap memory that has been allocated by an
unmanaged component with malloc()?

I get an exception when trying to use Marshal.FreeCoTaskMem() on the managed
pointer (of type IntPtr) returned from un-managed code as an "out" parameter.
In the C-dll this parameter is a double-pointer of my custom structure.

I think the reason is that there is no CoTaskMemAlloc() in the ANSI-C-style
DLL for allocating this pointer, just malloc().

Any suggestions for a good book or another source on PInvoke and Marshalling
different data types (including pointers) back and forth between managed and
unmanaged code (like C-style APIs)?

Any quide-lines for C# interoperability with ANSI-C code for multi-platforms
would be appreciated.


Valentina
 
It seems you must implement a special function my_free in your own unmanaged
code and call it from managed code.
Michael
 
Back
Top