public void updateVectorMsg(
string name,
ushort fid,
MamaMsg[] val)
{
// Check that the arguments are valid
if (val == null)
{
throw new ArgumentNullException("val");
}
// Check the array length
int numberMessages = val.Length;
if (numberMessages < 1)
{
throw new ArgumentOutOfRangeException("val");
}
// Verify that the native message has been created
EnsurePeerCreated();
// Allocate memory on the global native heap to pass the messages to the native layer
IntPtr globalHeapMemory = Marshal.AllocHGlobal(numberMessages * IntPtr.Size);
try
{
// Create a new array to hold all of the native handles
IntPtr[] nativeHandleArray = new IntPtr[numberMessages];
// Copy the native handles over
for (int nextItem = 0; nextItem < numberMessages; nextItem++)
{
nativeHandleArray[nextItem] = val[nextItem].nativeHandle;
}
// Copy this to the global heap
Marshal.Copy(nativeHandleArray, 0, globalHeapMemory, numberMessages);
// Call the native function
int code = NativeMethods.mamaMsg_updateVectorMsg(nativeHandle, name, fid, globalHeapMemory, numberMessages);
CheckResultCode(code);
}
finally
{
// Free the memory on the global heap now that the function has completed
Marshal.FreeHGlobal(globalHeapMemory);
}
}