Exemple #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;
        }
        /// <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();
        }
Exemple #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);
        }
Exemple #4
0
        /// <summary>
        /// Returns the rented pixel array back to the pool.
        /// </summary>
        private void ReturnPixels()
        {
            PixelDataPool <TPixel> .Return(this.PixelBuffer);

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

            this.pixelBuffer = null;
        }