private unsafe RioBufferSegment GetSegmentFromMemory(Memory <byte> memory) { var spanPtr = (IntPtr)memory.UnsafePointer; long startAddress; long spanAddress = spanPtr.ToInt64(); var bufferId = _rioThread.GetBufferId(spanPtr, out startAddress); checked { var offset = (uint)(spanAddress - startAddress); return(new RioBufferSegment(bufferId, offset, (uint)memory.Length)); } }
private unsafe RioBufferSegment GetSegmentFromMemory(Memory <byte> memory) { void *pointer; if (!memory.TryGetPointer(out pointer)) { throw new InvalidOperationException("Memory needs to be pinned"); } var spanPtr = (IntPtr)pointer; long startAddress; long spanAddress = spanPtr.ToInt64(); var bufferId = _rioThread.GetBufferId(spanPtr, out startAddress); checked { var offset = (uint)(spanAddress - startAddress); return(new RioBufferSegment(bufferId, offset, (uint)memory.Length)); } }
private RioBufferSegment GetSegmentFromSpan(BufferSpan span) { var bufferId = _rioThread.GetBufferId(span.BufferBasePtr); return(new RioBufferSegment(bufferId, (uint)span.Offset, (uint)span.Length)); }