public static void CopyTo <T>(UnsafeList *list, void *destination, int destinationIndex) where T : unmanaged { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } if (destinationIndex < 0) { throw new ArgumentOutOfRangeException(ThrowHelper.ArgumentOutOfRange_Index); } UDebug.Assert(list != null); UDebug.Assert(list->_items.Ptr != null); UDebug.Assert(typeof(T).TypeHandle.Value == list->_typeHandle); int numToCopy = list->_count; if (numToCopy == 0) { return; } UnsafeBuffer.CopyTo <T>(list->_items, 0, destination, destinationIndex, numToCopy); }
public static void CopyTo <T>(UnsafeQueue *queue, void *destination, int destinationIndex) where T : unmanaged { UDebug.Assert(queue != null); UDebug.Assert(queue->_items.Ptr != null); UDebug.Assert(typeof(T).TypeHandle.Value == queue->_typeHandle); UDebug.Assert(destination != null); UDebug.Assert(destinationIndex > -1); int numToCopy = queue->_count; if (numToCopy == 0) { return; } int bufferLength = queue->_items.Length; int head = queue->_head; int firstPart = Math.Min(bufferLength - head, numToCopy); UnsafeBuffer.CopyTo <T>(queue->_items, head, destination, destinationIndex, firstPart); numToCopy -= firstPart; if (numToCopy > 0) { UnsafeBuffer.CopyTo <T>(queue->_items, 0, destination, destinationIndex + bufferLength - head, numToCopy); } }
/// <summary> /// Returns a snapshot of the elements in the queue. /// </summary> /// <returns></returns> public static T[] ToArray <T>(UnsafeSPSCQueue *queue) where T : unmanaged { UDebug.Assert(queue != null); UDebug.Assert(queue->_items.Ptr != null); UDebug.Assert(typeof(T).TypeHandle.Value == queue->_typeHandle); var head = Volatile.Read(ref queue->_headAndTail.Head); var tail = Volatile.Read(ref queue->_headAndTail.Tail); var count = tail - head; if (count < 0) { count += queue->_items.Length; } if (count <= 0) { return(Array.Empty <T>()); } var arr = new T[count]; int numToCopy = count; int bufferLength = queue->_items.Length; int ihead = head; int firstPart = Math.Min(bufferLength - ihead, numToCopy); fixed(void *ptr = arr) { UnsafeBuffer.CopyTo <T>(queue->_items, ihead, ptr, 0, firstPart); numToCopy -= firstPart; if (numToCopy > 0) { UnsafeBuffer.CopyTo <T>(queue->_items, 0, ptr, 0 + bufferLength - ihead, numToCopy); } } return(arr); }
public static void CopyTo <T>(UnsafeRingBuffer *ringbuffer, void *destination, int destinationIndex) where T : unmanaged { if (destination == null) { throw new ArgumentNullException(nameof(destination)); } if (destinationIndex < 0) { throw new ArgumentOutOfRangeException(ThrowHelper.ArgumentOutOfRange_Index); } UDebug.Assert(ringbuffer != null); UDebug.Assert(ringbuffer->_items.Ptr != null); UDebug.Assert(typeof(T).TypeHandle.Value == ringbuffer->_typeHandle); int numToCopy = ringbuffer->_count; if (numToCopy == 0) { return; } int bufferLength = ringbuffer->_items.Length; int head = ringbuffer->_head; int firstPart = Math.Min(bufferLength - head, numToCopy); UnsafeBuffer.CopyTo <T>(ringbuffer->_items, head, destination, destinationIndex, firstPart); numToCopy -= firstPart; if (numToCopy > 0) { UnsafeBuffer.CopyTo <T>(ringbuffer->_items, 0, destination, destinationIndex + bufferLength - head, numToCopy); } }