/// ----------------------------------------------------------------------------------- /// <summary> /// Re-Allocates memory for <paramref name="nMaxSize"/> elements and returns a pointer /// suitable to be passed as array to a COM method. /// </summary> /// <param name="arrayPtr">Pointer with previously allocated memory</param> /// <param name="nMaxSize">Max. number of elements in the array</param> /// <typeparam name="T">Type of elements in array</typeparam> /// ----------------------------------------------------------------------------------- static public void ArrayToNative <T>(ref ArrayPtr arrayPtr, int nMaxSize) { arrayPtr.Resize(nMaxSize * SizeOf(typeof(T))); }
public void DoOwnMemory_1() { using (var array = new ArrayPtr(10)) Assert.AreEqual(true, array.OwnMemory, "Should own memory"); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Converts a managed array to a pointer to an unmanaged array that can /// be passed to a COM method. /// </summary> /// <param name="unmanagedObj">Unamanged array pointer</param> /// <param name="nMaxSize">Maximum size of the array</param> /// <param name="array">Managed array</param> /// <typeparam name="T">Type of elements in array</typeparam> /// <remarks>This method is only necessary for [out] or [in,out] arrays. For /// [in] arrays the .NET marshalling works.</remarks> /// ----------------------------------------------------------------------------------- static public void ArrayToNative <T>(ArrayPtr unmanagedObj, int nMaxSize, T[] array) { Debug.Assert(array.Length <= nMaxSize); CopyElements(unmanagedObj, array); }