public static UnmanagedMemoryBlock <T> Copy(void *address, int count)
        {
            var len = count * InfoOf <T> .Size;
            var ret = new UnmanagedMemoryBlock <T>(count);

            new UnmanagedMemoryBlock <T>((T *)address, count).CopyTo(ret);
            //source.AsSpan().CopyTo(ret.AsSpan()); //TODO! Benchmark at netcore 3.0, it should be faster than buffer.memorycopy.
            return(ret);
        }
        public static UnmanagedMemoryBlock <T> Copy(UnmanagedMemoryBlock <T> source)
        {
            var itemCount = source.Count;
            var len       = itemCount * InfoOf <T> .Size;
            var ret       = new UnmanagedMemoryBlock <T>(itemCount);

            source.CopyTo(ret);
            //source.AsSpan().CopyTo(ret.AsSpan()); //TODO! Benchmark at netcore 3.0, it should be faster than buffer.memorycopy.
            return(ret);
        }
        /// <summary>
        ///     Copies the entire contents of this storage to given address (using <see cref="Count"/>).
        /// </summary>
        /// <param name="dst">The block to copy to.</param>
        public static unsafe void CopyTo <T>(this UnmanagedMemoryBlock <T> src, UnmanagedMemoryBlock <T> dst) where T : unmanaged
        {
            if (src.Count > dst.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(dst), $"Unable to copy from this storage to given array because this storage count is larger than the given array length.");
            }

            var bytesCount = src.BytesCount;

            Buffer.MemoryCopy(src.Address, dst.Address, bytesCount, bytesCount);
        }
        public static UnmanagedMemoryBlock <T> FromArray(T[] arr, bool copy)
        {
            if (!copy)
            {
                return(new UnmanagedMemoryBlock <T>(GCHandle.Alloc(arr, GCHandleType.Pinned), arr.Length));
            }

            var ret = new UnmanagedMemoryBlock <T>(arr.Length);

            new Span <T>(arr).CopyTo(ret.AsSpan());

            return(ret);
        }
        public static UnmanagedMemoryBlock <T> FromArray(T[,,,,,,,,,,,,,,,] arr, bool copy)
        {
            if (!copy)
            {
                return(new UnmanagedMemoryBlock <T>(GCHandle.Alloc(arr, GCHandleType.Pinned), arr.Length));
            }

            var ret = new UnmanagedMemoryBlock <T>(arr.Length);

            fixed(T *arrptr = arr)
            {
                new UnmanagedMemoryBlock <T>(arrptr, arr.Length).CopyTo(ret);
            }

            return(ret);
        }