Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Buffer{T}"/> class.
        /// </summary>
        /// <param name="length">The desired count of elements. (Minimum size for <see cref="Array"/>)</param>
        public Buffer(int length)
        {
            this.Length = length;
            this.Array  = PixelDataPool <T> .Rent(length);

            this.isPoolingOwner = true;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PinnedBuffer{T}"/> class.
        /// </summary>
        /// <param name="count">The desired count of elements. (Minimum size for <see cref="Array"/>)</param>
        public PinnedBuffer(int count)
        {
            this.Count = count;
            this.Array = PixelDataPool <T> .Rent(count);

            this.isPoolingOwner = true;
            this.Pin();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Disposes the <see cref="PinnedBuffer{T}"/> instance by unpinning the array, and returning the pooled buffer when necessary.
        /// </summary>
        public void Dispose()
        {
            if (this.IsDisposedOrLostArrayOwnership)
            {
                return;
            }

            this.IsDisposedOrLostArrayOwnership = true;
            this.UnPin();

            if (this.isPoolingOwner)
            {
                PixelDataPool <T> .Return(this.Array);
            }

            this.Array = null;
            this.Count = 0;

            GC.SuppressFinalize(this);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns the rented pixel array back to the pool.
        /// </summary>
        private void ReturnPixels()
        {
            PixelDataPool <TPixel> .Return(this.PixelBuffer);

            this.PixelBuffer = null;
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Rents the pixel array from the pool.
 /// </summary>
 private void RentPixels()
 {
     this.PixelBuffer = PixelDataPool <TPixel> .Rent(this.Width *this.Height);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns the rented pixel array back to the pool.
        /// </summary>
        private void ReturnPixels()
        {
            PixelDataPool <TColor> .Return(this.pixelBuffer);

            this.pixelBuffer = null;
        }