public static AiNativeArray <T> ToNativeArray <T>(this T[] source) where T : unmanaged
        {
            AiNativeArray <T> destination = new AiNativeArray <T>(source.Length);

            MemoryCopy.Copy(source, 0, destination.GetUnsafePtr(), 0, destination.SizeOf);
            return(destination);
        }
 public static void CopyTo <T>(this AiNativeArray <T> array, T[] target) where T : unmanaged
 {
     if (target.Length < array.Length)
     {
         throw new ArgumentException("Destination array is smaller then source array");
     }
     MemoryCopy.Copy(array.GetUnsafePtr(), target, array.SizeOf);
 }
        public static AiNativeArray <T> ToNativeArray <T>(this byte[] source) where T : unmanaged
        {
            if (source.Length % UnsafeCollectionUtility.SizeOf <T>() != 0)
            {
                throw new ArgumentException("Invalid length for type");
            }

            int size = source.Length / UnsafeCollectionUtility.SizeOf <T>();
            AiNativeArray <T> destination = new AiNativeArray <T>(size);

            MemoryCopy.Copy(source, 0, destination.GetUnsafePtr(), 0, source.Length);
            return(destination);
        }
Esempio n. 4
0
        public static UnsafeListData *CreateFrom <T>(AiNativeArray <T> array) where T : unmanaged
        {
            UnsafeListData *listData = Create(UnsafeCollectionUtility.SizeOf <T>(), array.Length);

            if (listData->Capacity < array.Length)
            {
                listData->Dispose();
                throw new Exception("Unknown Error");
            }
            listData->Length = array.Length;

            int bytesToCopy = array.Length * UnsafeCollectionUtility.SizeOf <T>();

            Buffer.MemoryCopy(array.GetUnsafePtr(), listData->Ptr, bytesToCopy, bytesToCopy);

            return(listData);
        }
 public static T[] ToArray <T>(this AiNativeArray <T> array) where T : unmanaged
 {
     T[] target = new T[array.Length];
     MemoryCopy.Copy(array.GetUnsafePtr(), target, array.SizeOf);
     return(target);
 }
 public static byte[] ToByteArray <T>(this AiNativeArray <T> array) where T : unmanaged
 {
     byte[] target = new byte[array.SizeOf];
     MemoryCopy.Copy(array.GetUnsafePtr(), 0, target, 0, array.SizeOf);
     return(target);
 }