/// <summary> /// Executes a collection cycle on the pages in this list. /// </summary> /// <param name="shiftLevel">the number of bits to shift the referenced counter by. /// Value may be zero but cannot be negative</param> /// <param name="excludedList">A set of values to exclude from the collection process</param> /// <param name="e">Arguments for the collection.</param> /// <returns>The number of pages returned to the memory pool</returns> /// <remarks>If the collection mode is Emergency or Critical, it will only release the required number of pages and no more</remarks> //ToDo: Since i'll be parsing the entire list, rebuilding a new sorted tree may be quicker than removing individual blocks and copying. //ToDo: Also, I should probably change the ShouldCollect callback to an IEnumerable<int>. public int DoCollection(int shiftLevel, HashSet <int> excludedList, CollectionEventArgs e) { if (m_disposed) { throw new ObjectDisposedException(GetType().FullName); } if (shiftLevel < 0) { throw new ArgumentOutOfRangeException("shiftLevel", "must be non negative"); } int collectionCount = 0; int maxCollectCount = -1; if (e.CollectionMode == MemoryPoolCollectionMode.Emergency || e.CollectionMode == MemoryPoolCollectionMode.Critical) { maxCollectCount = e.DesiredPageReleaseCount; } for (int x = 0; x < m_pageIndexLookupByPositionIndex.Count; x++) { int pageIndex = m_pageIndexLookupByPositionIndex.Values[x]; InternalPageMetaData block = m_listOfPages.GetValue(pageIndex); block.ReferencedCount >>= shiftLevel; m_listOfPages.OverwriteValue(pageIndex, block); if (block.ReferencedCount == 0) { if (maxCollectCount != collectionCount) { if (!excludedList.Contains(pageIndex)) { collectionCount++; m_pageIndexLookupByPositionIndex.RemoveAt(x); x--; m_listOfPages.SetNull(pageIndex); e.ReleasePage(block.MemoryPoolIndex); } } } } return(collectionCount); }
private static void BufferPool_RequestCollection(object sender, CollectionEventArgs eventArgs) { if (lst == null) { return; } if (eventArgs.CollectionMode == MemoryPoolCollectionMode.Critical) { int ItemsToRemove = lst.Count / 5; while (lst.Count > ItemsToRemove) { eventArgs.ReleasePage(lst[lst.Count - 1]); lst.RemoveAt(lst.Count - 1); } //for (int x = 0; x<lst.Count; x+=3) //{ // BufferPool.ReleasePage(lst[x]); // lst.RemoveAt(x); // x -= 1; //} } //throw new NotImplementedException(); }
private static void BufferPool_RequestCollection(object sender, CollectionEventArgs eventArgs) { if (lst == null) return; if (eventArgs.CollectionMode == MemoryPoolCollectionMode.Critical) { int ItemsToRemove = lst.Count / 5; while (lst.Count > ItemsToRemove) { eventArgs.ReleasePage(lst[lst.Count - 1]); lst.RemoveAt(lst.Count - 1); } //for (int x = 0; x<lst.Count; x+=3) //{ // BufferPool.ReleasePage(lst[x]); // lst.RemoveAt(x); // x -= 1; //} } //throw new NotImplementedException(); }