pin_ptr vs malloc for unmanaged array

  • Thread starter Thread starter _DS
  • Start date Start date
D

_DS

My managed code needs to shuttle an unmanaged buffer between a couple
unmanaged functions. I know this could be done via pin_ptr, and I
understand the implications re managed heap fragmentation (I'll set it
up at the start of the program and leave it).

I believe that this could also be done by old-fashioned #include
<malloc.h> with standard allocators. Is there any reason to prefer
malloc over a pinned ptr?

Given that I may need to access the buffer in C#, I was leaning toward
a pinned pointer. Is there an advantage in Malloc that would outweigh
that?
 
_DS said:
My managed code needs to shuttle an unmanaged buffer between a couple
unmanaged functions. I know this could be done via pin_ptr, and I
understand the implications re managed heap fragmentation (I'll set it
up at the start of the program and leave it).

I believe that this could also be done by old-fashioned #include
<malloc.h> with standard allocators. Is there any reason to prefer
malloc over a pinned ptr?

Given that I may need to access the buffer in C#, I was leaning toward
a pinned pointer. Is there an advantage in Malloc that would outweigh
that?

If you need to access the buffer from managed code then you must allocate it
on the managed heap and pin it for use by your unmanaged code.

-cd
 
Back
Top