public BufferHandle Retain(bool pin = false) { BufferHandle bufferHandle; if (pin) { if (_owner != null) { bufferHandle = _owner.Pin(_index); } else { var handle = GCHandle.Alloc(_array, GCHandleType.Pinned); unsafe { var pointer = OwnedBuffer <T> .Add((void *)handle.AddrOfPinnedObject(), _index); bufferHandle = new BufferHandle(null, pointer, handle); } } } else { if (_owner != null) { _owner.Retain(); } bufferHandle = new BufferHandle(_owner); } return(bufferHandle); }
public BufferHandle Retain(bool pin = false) { BufferHandle bufferHandle; if (pin) { if (_index < 0) { bufferHandle = Unsafe.As <OwnedBuffer <T> >(_arrayOrOwnedBuffer).Pin(_index & bitMask); } else { var handle = GCHandle.Alloc(Unsafe.As <T[]>(_arrayOrOwnedBuffer), GCHandleType.Pinned); unsafe { var pointer = OwnedBuffer <T> .Add((void *)handle.AddrOfPinnedObject(), _index); bufferHandle = new BufferHandle(null, pointer, handle); } } } else { if (_index < 0) { Unsafe.As <OwnedBuffer <T> >(_arrayOrOwnedBuffer).Retain(); bufferHandle = new BufferHandle(Unsafe.As <OwnedBuffer <T> >(_arrayOrOwnedBuffer)); } else { bufferHandle = new BufferHandle(null); } } return(bufferHandle); }