To allocate memory in managed code i use:
IntPtr [] params_list_n = new IntPtr [5];
But for unmanaged memory i use Marshal.AllocHGlobal
And I do not understand how, in this case to allocate memory for the array.
Ideally I want to use the function call Marshal.GetNativeVariantForObject (o, params_list_n[i]);
For each element of the array.
Creating unmanaged memory using Marshal.AllocHGlobal is simple.
IntPtr pointer = Marshal.AllocHGlobal(1024);
If you need to calculate the amount of space you can use Marshal.SizeOf.
int size = Marshal.SizeOf(typeof(IntPtr));
IntPtr pointer = Marshal.AllocHGlobal(size);
You will also need to enable unsafe code
in your project for this to run.
Properties
.Build
tab.Allow unsafe code
.