public void SetBuffers() { Assert.Throws <ArgumentNullException> (() => { encoder.SetBuffers(null, new nuint [0], new NSRange()); }, "Null buffers should throw."); Assert.Throws <ArgumentNullException> (() => { encoder.SetBuffers(new IMTLBuffer [0], null, new NSRange()); }, "Null offsets should throw."); // assert we do not crash or throw, we are testing the extension method Assert.DoesNotThrow(() => { encoder.SetBuffers(new IMTLBuffer [0], new nuint [0], new NSRange()); }, "Should not throw"); }
public static void SetBuffers(this IMTLArgumentEncoder encoder, IMTLBuffer[] buffers, nuint[] offsets, NSRange range) { if (buffers == null) { throw new ArgumentNullException(nameof(buffers)); } if (offsets == null) { throw new ArgumentNullException(nameof(offsets)); } var bufferPtrArray = buffers.Length <= 1024 ? stackalloc IntPtr[buffers.Length] : new IntPtr [buffers.Length]; // get all intptr from the array to pass to the lower level call for (var i = 0; i < buffers.Length; i++) { bufferPtrArray [i] = buffers [i].Handle; } unsafe { fixed(void *buffersPtr = bufferPtrArray) fixed(void *offsetsPtr = offsets) // can use fixed { encoder.SetBuffers((IntPtr)buffersPtr, (IntPtr)offsetsPtr, range); } } GC.KeepAlive(buffers) }
public unsafe static void SetBuffers(this IMTLArgumentEncoder This, IMTLBuffer [] buffers, nint [] offsets, Foundation.NSRange range) { fixed(void *handle = offsets) This.SetBuffers(buffers, (IntPtr)handle, range); }