I have a specific issue passing enum
from managed to unmanaged layer - basically with pinning the enum
array.
My use case is I have a 1D array of reference type (T) which contains a buffer (2D array of enum
backed by byte).
buffer (2D Array of enum
backed by byte) is allocated on managed heap and I want to pass that buffer to unmanaged layer - to fill it with some values. At the same time I want to make sure that Garbage Collector (GC) does not move the buffer around when unmanaged method is filling in data to the buffer. In order to do that I have to pin the buffer. The language that I am using for managed code is C++/CLI,
which provides 2 way of pinning the buffer
cli::pin_ptr
GCHandle
For some reason I cannot pin buffer using GCHandle
- I get ArgumentException
- may be because enum
is non-blittable type.
I can pin buffer with cli::pin_ptr
though, however problem with cli::pin_ptr
is that because array of reference type in discussion, (which contains buffer - 2D array of enum backed by byte), can be variable length, I will need more than one pin_ptr
(array of pin_ptr
) to pin buffer in each reference type instance. And I cannot have array of cli::pin_ptr
.
This is blocking me for implementing specific feature in .NET Application - as I cannot pin the 2D array of enum
correctly.