I have some native C/C++ code that calls a C# delegate as callback. What's the best practice to pass a dynamic array argument? Actually the C pointer is a data member of a struct and I pass the struct to the callback.
Is it OK to do something like this using IntPtr?
struct Data {
... (other data members)
double* array;
int size;
};
Array is a pointer to an array allocated in my C++ code (just a call to new or malloc). On the C# side the delegate would expect
struct Data {
... (other data members)
IntPtr array;
int size;
}
My concern is... should IntPtr be memory allocated using Marshal.AllocHGlobal or is it also safe if it's memory allocated in my C++ code (new or malloc)?