[Mono-dev] OracleClient.Oci and GC
Rodrigo Kumpera
kumpera at gmail.com
Fri Aug 22 15:31:47 UTC 2014
Hey Neale,
You can safely pass interior pointers to pinvoke without fearing the object
been collected for the duration of the call.
Mind that you have to correctly use specify in/out/ref depending on the
copy semantics you need.
Problems only arise when native keeps that pointer after the call finishes,
this can result in the object been moved
as the GC has no visibility into the native heap.
For those cases you can either create a pinning GC handle to the victim
object or you can allocate a chunk of native
memory that will be shared between managed and native to store the desired
value. Both options suck, TBH.
I'd say go with the native chunk of code if you can't lexically scope the
pinning regions, it will be more reliable as
failing to dispose the object won't lead to permanent leaks.
On Fri, Aug 22, 2014 at 11:11 AM, Neale Ferguson <NealeFerguson at verizon.net>
wrote:
> Is that just a comment on my ref IntPtr question or the use of ref with
> the OCIxxxx stuff in general?
>
> On Aug 22, 2014, at 10:45 AM, Rodrigo Kumpera <kumpera at gmail.com> wrote:
>
> > Mono does conservative scanning of the native stack, so once the pointer
> has crossed over to native, the containing object will remain pinned.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20140822/c8bfd7da/attachment-0001.html>
More information about the Mono-devel-list
mailing list