Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new page-locked 1D array.
        /// </summary>
        /// <param name="accelerator">The parent accelerator.</param>
        /// <param name="extent">The number of elements to allocate.</param>
        /// <param name="uninitialized">True, to allocate an uninitialized array.</param>
        internal unsafe PageLockedArray1D(
            Accelerator accelerator,
            LongIndex1D extent,
            bool uninitialized)
        {
            if (extent < 0L)
            {
                throw new ArgumentOutOfRangeException(nameof(extent));
            }
#if NET5_0
            array = uninitialized
                ? GC.AllocateUninitializedArray <T>(extent.ToIntIndex(), pinned: true)
                : GC.AllocateArray <T>(extent.ToIntIndex(), pinned: true);

            fixed(T *ptr = array)
            Initialize(accelerator, new IntPtr(ptr), extent);
#else
            Trace.WriteLineIf(
                uninitialized,
                RuntimeErrorMessages.NotSupportedUninitalizedArrayInitialization);
            array  = new T[extent];
            handle = GCHandle.Alloc(array, GCHandleType.Pinned);
            Initialize(accelerator, handle.AddrOfPinnedObject(), extent);
#endif
        }
Ejemplo n.º 2
0
 /// <summary cref="ISequencer{T}.ComputeSequenceElement(Index1)"/>
 public int ComputeSequenceElement(LongIndex1D sequenceIndex) => MaxValue - sequenceIndex.ToIntIndex();