Beispiel #1
0
        /// <summary>
        /// Allocates a buffer of value type objects interpreted as a 2D region
        /// of <paramref name="width"/> x <paramref name="height"/> elements.
        /// </summary>
        /// <typeparam name="T">The type of buffer items to allocate.</typeparam>
        /// <param name="memoryAllocator">The memory allocator.</param>
        /// <param name="width">The buffer width.</param>
        /// <param name="height">The buffer height.</param>
        /// <param name="options">The allocation options.</param>
        /// <returns>The <see cref="Buffer2D{T}"/>.</returns>
        public static Buffer2D <T> Allocate2D <T>(
            this MemoryAllocator memoryAllocator,
            int width,
            int height,
            AllocationOptions options = AllocationOptions.None)
            where T : struct
        {
            long            groupLength = (long)width * height;
            MemoryGroup <T> memoryGroup = memoryAllocator.AllocateGroup <T>(groupLength, width, options);

            return(new Buffer2D <T>(memoryGroup, width, height));
        }
Beispiel #2
0
        internal static Buffer2D <T> Allocate2DOveraligned <T>(
            this MemoryAllocator memoryAllocator,
            int width,
            int height,
            int alignmentMultiplier,
            AllocationOptions options = AllocationOptions.None)
            where T : struct
        {
            long            groupLength = (long)width * height;
            MemoryGroup <T> memoryGroup = memoryAllocator.AllocateGroup <T>(
                groupLength,
                width * alignmentMultiplier,
                options);

            return(new Buffer2D <T>(memoryGroup, width, height));
        }
        /// <summary>
        /// Allocates a buffer of value type objects interpreted as a 2D region
        /// of <paramref name="width"/> x <paramref name="height"/> elements.
        /// </summary>
        /// <typeparam name="T">The type of buffer items to allocate.</typeparam>
        /// <param name="memoryAllocator">The memory allocator.</param>
        /// <param name="width">The buffer width.</param>
        /// <param name="height">The buffer height.</param>
        /// <param name="preferContiguosImageBuffers">A value indicating whether the allocated buffer should be contiguous, unless bigger than <see cref="int.MaxValue"/>.</param>
        /// <param name="options">The allocation options.</param>
        /// <returns>The <see cref="Buffer2D{T}"/>.</returns>
        public static Buffer2D <T> Allocate2D <T>(
            this MemoryAllocator memoryAllocator,
            int width,
            int height,
            bool preferContiguosImageBuffers,
            AllocationOptions options = AllocationOptions.None)
            where T : struct
        {
            long            groupLength = (long)width * height;
            MemoryGroup <T> memoryGroup;

            if (preferContiguosImageBuffers && groupLength < int.MaxValue)
            {
                IMemoryOwner <T> buffer = memoryAllocator.Allocate <T>((int)groupLength, options);
                memoryGroup = MemoryGroup <T> .CreateContiguous(buffer, false);
            }
            else
            {
                memoryGroup = memoryAllocator.AllocateGroup <T>(groupLength, width, options);
            }

            return(new Buffer2D <T>(memoryGroup, width, height));
        }