Is it possible to pin an array using reflection?
I have an interpreter I'm working on and I'd like to support some usage of pointers, but right now all .NET interop is based on reflection or calls to functions I've defined ahead of time. As far as I can tell there's not a way for me to pin an array through a reflection call, but I want to avoid emitting a dynamic method because that won't work on iOS/AOT
Alternatively I was thinking maybe there's a way I can pin the array without using fixed so then the duration of the pin is managed manually by me? Not sure if there's something like GCHandle that can help me out here
2 Replies
I suppose I could create a host function that takes an array and a callback function that takes a pointer, and use fixed there
yes, you can do that, or use a pinned GCHandle (GCHandleType.Pinned)