Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ TryPrepareScatterGatherBuffers< T, THandler >()

static unsafe bool System.IO.RandomAccess.TryPrepareScatterGatherBuffers< T, THandler > ( IReadOnlyList< T > buffers,
THandler handler,
[NotNullWhen(true)] out MemoryHandle[] handlesToDispose,
out IntPtr segmentsPtr,
out int totalBytes )
inlinestaticprivate
Type Constraints
THandler :struct 
THandler :IMemoryHandler<T> 

Definition at line 532 of file RandomAccess.cs.

532 : struct, IMemoryHandler<T>
533 {
534 int num = s_cachedPageSize;
535 long num2 = num - 1;
536 int count = buffers.Count;
537 handlesToDispose = null;
538 segmentsPtr = IntPtr.Zero;
539 totalBytes = 0;
540 long* ptr = null;
541 bool flag = false;
542 try
543 {
544 long num3 = 0L;
545 for (int i = 0; i < count; i++)
546 {
547 T memory = buffers[i];
548 int length = handler.GetLength(in memory);
549 num3 += length;
550 if (length != num || num3 > int.MaxValue)
551 {
552 return false;
553 }
554 MemoryHandle memoryHandle = handler.Pin(in memory);
555 long num4 = (long)memoryHandle.Pointer;
556 if ((num4 & num2) != 0L)
557 {
558 memoryHandle.Dispose();
559 return false;
560 }
562 if (ptr == null)
563 {
564 ptr = (long*)NativeMemory.Alloc((nuint)count + (nuint)1u, 8u);
565 ptr[count] = 0L;
566 }
567 ptr[i] = num4;
568 }
570 totalBytes = (int)num3;
571 flag = true;
572 return handlesToDispose != null;
573 }
574 finally
575 {
576 if (!flag)
577 {
579 }
580 }
581 }
static unsafe void CleanupScatterGatherBuffers(MemoryHandle[] handlesToDispose, IntPtr segmentsPtr)
static readonly int s_cachedPageSize
static unsafe void * Alloc(nuint elementCount, nuint elementSize)

References System.Runtime.InteropServices.NativeMemory.Alloc(), System.buffers, System.IO.RandomAccess.CleanupScatterGatherBuffers(), System.count, System.L, System.length, System.IO.RandomAccess.s_cachedPageSize, and System.IntPtr.Zero.