GSF.IO.Unmanaged.MemoryPoolPageList.ShrinkMemoryPool C# (CSharp) Method

ShrinkMemoryPool() public method

Tries to shrink the buffer pool to the provided size
The buffer pool shrinks to a size less than or equal to size.
public ShrinkMemoryPool ( long size ) : long
size long The size of the buffer pool
return long
        public long ShrinkMemoryPool(long size)
        {
            lock (m_syncRoot)
            {
                if (m_disposed)
                    throw new ObjectDisposedException(GetType().FullName);

                if (CurrentCapacity <= size)
                    return CurrentCapacity;

                for (int x = 0; x < m_memoryBlocks.Capacity; x++)
                {

                    if (m_memoryBlocks[x] != null)
                    {
                        if (m_isPageFree.AreAllBitsCleared(x * m_pagesPerMemoryBlock, m_pagesPerMemoryBlock))
                        {
                            m_memoryBlocks[x].Dispose();
                            m_memoryBlocks[x] = null;
                            m_memoryBlockAllocations--;
                            if (CurrentCapacity <= size)
                                return CurrentCapacity;
                        }
                    }
                }
                return CurrentCapacity;
            }
        }