public Buffer <T> CreateBuffer <T>(MemoryFlags flags, long size, IntPtr hostAddress) where T : struct { if (size < 0) { throw new ArgumentOutOfRangeException(nameof(size)); } else if (size == 0) { throw new ArgumentException("Invalid buffer size.", nameof(size)); } if (hostAddress == IntPtr.Zero && (flags & (MemoryFlags.UseHostPointer | MemoryFlags.CopyHostPointer)) != 0) { throw new ArgumentException("Invalid host address.", nameof(hostAddress)); } if (hostAddress != IntPtr.Zero && (flags & (MemoryFlags.UseHostPointer | MemoryFlags.CopyHostPointer)) == 0) { throw new ArgumentException("Invalid host address.", nameof(hostAddress)); } BufferSafeHandle handle = UnsafeNativeMethods.CreateBuffer(Handle, flags, (IntPtr)size, hostAddress); return(new Buffer <T>(this, handle)); }