/// <summary> /// Reallocates the unmanaged array to be new size. This may require a new location in memory. /// </summary> /// <param name="size"></param> public void Realloc(int size) { var ptr = Marshal.ReAllocHGlobal(Array.Ptr, new IntPtr(size)); Array = new UnmanagedArray <T>(ptr, size); }
/// <summary> /// Allocates a new instance of the AutomaticUnmanagedArray, specifying the size of the array as the number /// of instances in the array (not the number of bytes). /// </summary> /// <param name="size"></param> public AutomaticUnmanagedArray(int size) { var ptr = Marshal.AllocHGlobal(size * Marshal.SizeOf <T>()); Array = new UnmanagedArray <T>(ptr, size); }