I would like to ask a question that is obvious to all people porting
applications from the "traditional" C\VB6 interop scheme choosing C# vs
VB.NET.
We have a math library in C which ubiquitously takes a float* which
represents an array of floats. If the memory is allocated by the client,
in C# or VB.NET, I assume it must be "fixed" so that the GC does not
move the pointer during the C algorithm. Given that we are choosing
between C# and VB.NET, how is this done in either language? Is it even
possible in VB.NET. In terms of C#, I have heard that using the keyword
"fixed" is much faster then Marshal.AllocHGlobal. Is there a way to
offload this step into the C dll.
The question centers around these points:
1) Given a float* in the signature of a C dll is it required to fix that
pointer for the C function to be reliable when the memory is allocated
in managed code?
2) If (1) is true, is Marshal.AllocHGlobal the only way to do that in VB.NET
3) If (2) is there a way to offload that step to the C dll.
4) C# seems to lean more toward operating with interop easier, what
about this particular scenario?
I assumed that this question's answer would be easy to find using
google, but have not found this the case.
Thank you.