/// <summary> /// Tries to shrink the buffer pool to the provided size /// </summary> /// <param name="size">The size of the buffer pool</param> /// <returns>The final size of the buffer pool</returns> /// <remarks>The buffer pool shrinks to a size less than or equal to <see cref="size"/>.</remarks> //ToDo: Expose this method and test it. 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); } }
public void GetSetBits() { BitArray array = new BitArray(false, 15); for (int x = 0; x < 15; x++) { if (array[x]) { throw new Exception(); } } for (int x = 0; x < 15; x++) { if (array.GetBitUnchecked(x)) { throw new Exception(); } } array[1] = true; if (array.TrySetBit(1)) { throw new Exception(); } if (!array.TrySetBit(2)) { throw new Exception(); } if (array.TrySetBit(2)) { throw new Exception(); } if (!array.TryClearBit(2)) { throw new Exception(); } if (array.TryClearBit(2)) { throw new Exception(); } //Here, bit 1 is set. if (!array.AreAllBitsSet(1, 1)) { throw new Exception(); } if (array.AreAllBitsSet(1, 3)) { throw new Exception(); } if (!array.AreAllBitsCleared(2, 8)) { throw new Exception(); } if (array.AreAllBitsCleared(0, 8)) { throw new Exception(); } array.SetBits(1, 8); if (!array.AreAllBitsSet(1, 8)) { throw new Exception(); } array.ClearBits(1, 8); if (!array.AreAllBitsCleared(1, 8)) { throw new Exception(); } array.EnsureCapacity(62); if (!array.AreAllBitsCleared(1, 8)) { throw new Exception(); } array.EnsureCapacity(1000); if (!array.AreAllBitsCleared(62, 500)) { throw new Exception(); } }
public void GetSetBits() { BitArray array = new BitArray(false, 15); for (int x = 0; x < 15; x++) { if (array[x]) throw new Exception(); } for (int x = 0; x < 15; x++) { if (array.GetBitUnchecked(x)) throw new Exception(); } array[1] = true; if(array.TrySetBit(1)) throw new Exception(); if (!array.TrySetBit(2)) throw new Exception(); if (array.TrySetBit(2)) throw new Exception(); if (!array.TryClearBit(2)) throw new Exception(); if (array.TryClearBit(2)) throw new Exception(); //Here, bit 1 is set. if (!array.AreAllBitsSet(1,1)) throw new Exception(); if (array.AreAllBitsSet(1,3)) throw new Exception(); if (!array.AreAllBitsCleared(2,8)) throw new Exception(); if (array.AreAllBitsCleared(0, 8)) throw new Exception(); array.SetBits(1,8); if (!array.AreAllBitsSet(1,8)) throw new Exception(); array.ClearBits(1, 8); if (!array.AreAllBitsCleared(1, 8)) throw new Exception(); array.EnsureCapacity(62); if (!array.AreAllBitsCleared(1, 8)) throw new Exception(); array.EnsureCapacity(1000); if (!array.AreAllBitsCleared(62, 500)) throw new Exception(); }