Пример #1
0
 public static unsafe void Copy(
     NativeArrayNoLeakDetection <T> src,
     int srcIndex,
     NativeArrayNoLeakDetection <T> dst,
     int dstIndex,
     int length)
 {
     AtomicSafetyHandle.CheckReadAndThrow(src.m_Safety);
     AtomicSafetyHandle.CheckWriteAndThrow(dst.m_Safety);
     if (length < 0)
     {
         throw new ArgumentOutOfRangeException(nameof(length), "length must be equal or greater than zero.");
     }
     if (srcIndex < 0 || srcIndex > src.Length || srcIndex == src.Length && src.Length > 0)
     {
         throw new ArgumentOutOfRangeException(nameof(srcIndex), "srcIndex is outside the range of valid indexes for the source NativeArray2.");
     }
     if (dstIndex < 0 || dstIndex > dst.Length || dstIndex == dst.Length && dst.Length > 0)
     {
         throw new ArgumentOutOfRangeException(nameof(dstIndex), "dstIndex is outside the range of valid indexes for the destination NativeArray2.");
     }
     if (srcIndex + length > src.Length)
     {
         throw new ArgumentException("length is greater than the number of elements from srcIndex to the end of the source NativeArray2.", nameof(length));
     }
     if (dstIndex + length > dst.Length)
     {
         throw new ArgumentException("length is greater than the number of elements from dstIndex to the end of the destination NativeArray2.", nameof(length));
     }
     UnsafeUtility.MemCpy((void *)((IntPtr)dst.m_Buffer + (dstIndex * UnsafeUtility.SizeOf <T>())), (void *)((IntPtr)src.m_Buffer + (srcIndex * UnsafeUtility.SizeOf <T>())), (long)(length * UnsafeUtility.SizeOf <T>()));
 }
Пример #2
0
        private static unsafe void Allocate(int length, Allocator allocator, out NativeArrayNoLeakDetection <T> array)
        {
            long size = (long)UnsafeUtility.SizeOf <T>() * (long)length;

            if (allocator <= Allocator.None)
            {
                throw new ArgumentException("Allocator must be Temp, TempJob or Persistent", nameof(allocator));
            }
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length), "Length must be >= 0");
            }
            IsBlittableAndThrow();
            if (size > (long)int.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(length), string.Format("Length * sizeof(T) cannot exceed {0} bytes", (object)int.MaxValue));
            }
            array.m_Buffer         = UnsafeUtility.Malloc(size, UnsafeUtility.AlignOf <T>(), allocator);
            array.m_Length         = length;
            array.m_AllocatorLabel = allocator;
            array.m_MinIndex       = 0;
            array.m_MaxIndex       = length - 1;
            array.m_Safety         = AtomicSafetyHandle.Create();
            //DisposeSentinel.Create(out array.m_Safety, out array.m_DisposeSentinel, 1, allocator);
        }
Пример #3
0
 public static void Copy(NativeArrayNoLeakDetection <T> src, T[] dst)
 {
     AtomicSafetyHandle.CheckReadAndThrow(src.m_Safety);
     if (src.Length != dst.Length)
     {
         throw new ArgumentException("source and destination length must be the same");
     }
     Copy(src, 0, dst, 0, src.Length);
 }
Пример #4
0
        public static unsafe void Copy(
            T[] src,
            int srcIndex,
            NativeArrayNoLeakDetection <T> dst,
            int dstIndex,
            int length)
        {
            AtomicSafetyHandle.CheckWriteAndThrow(dst.m_Safety);
            if (src == null)
            {
                throw new ArgumentNullException(nameof(src));
            }
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length), "length must be equal or greater than zero.");
            }
            if (srcIndex < 0 || srcIndex > src.Length || srcIndex == src.Length && src.Length > 0)
            {
                throw new ArgumentOutOfRangeException(nameof(srcIndex), "srcIndex is outside the range of valid indexes for the source array.");
            }
            if (dstIndex < 0 || dstIndex > dst.Length || dstIndex == dst.Length && dst.Length > 0)
            {
                throw new ArgumentOutOfRangeException(nameof(dstIndex), "dstIndex is outside the range of valid indexes for the destination NativeArray2.");
            }
            if (srcIndex + length > src.Length)
            {
                throw new ArgumentException("length is greater than the number of elements from srcIndex to the end of the source array.", nameof(length));
            }
            if (dstIndex + length > dst.Length)
            {
                throw new ArgumentException("length is greater than the number of elements from dstIndex to the end of the destination NativeArray2.", nameof(length));
            }
            GCHandle gcHandle = GCHandle.Alloc((object)src, GCHandleType.Pinned);
            IntPtr   num      = gcHandle.AddrOfPinnedObject();

            UnsafeUtility.MemCpy((void *)((IntPtr)dst.m_Buffer + (dstIndex * UnsafeUtility.SizeOf <T>())), (void *)(num + (srcIndex * UnsafeUtility.SizeOf <T>())), (long)(length * UnsafeUtility.SizeOf <T>()));
            gcHandle.Free();
        }
Пример #5
0
 public NativeArrayNoLeakDetection(NativeArrayNoLeakDetection <T> array, Allocator allocator)
 {
     Allocate(array.Length, allocator, out this);
     Copy(array, this);
 }
Пример #6
0
 public NativeArray2DebugView(NativeArrayNoLeakDetection <T> array)
 {
     m_Array = array;
 }
Пример #7
0
 public Enumerator(ref NativeArrayNoLeakDetection <T> array)
 {
     m_Array = array;
     m_Index = -1;
 }
Пример #8
0
 public static void Copy(NativeArrayNoLeakDetection <T> src, T[] dst, int length)
 {
     Copy(src, 0, dst, 0, length);
 }
Пример #9
0
 public unsafe bool Equals(NativeArrayNoLeakDetection <T> other)
 {
     return(m_Buffer == other.m_Buffer && m_Length == other.m_Length);
 }
Пример #10
0
 public void CopyTo(NativeArrayNoLeakDetection <T> array)
 {
     Copy(this, array);
 }
Пример #11
0
 public void CopyFrom(NativeArrayNoLeakDetection <T> array)
 {
     Copy(array, this);
 }