コード例 #1
0
        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);
        }
コード例 #2
0
 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);
 }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: UnsafeListData.cs プロジェクト: taotao111/ainav
        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);
        }
コード例 #5
0
 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);
 }
コード例 #6
0
 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);
 }