Example #1
0
        private void InternalEventPagesReleased(PagesInUse pages)
        {
            // if these previously in use pages are contiguous with a free block of pages, add them to that block.
            bool block_found = false;
            for (int i = 0; i < m_EmptyPages.Count; i++)
            {
                if (m_EmptyPages[i].FirstPage == pages.FollowingPage)
                {
                    m_EmptyPages[i].FirstPage = pages.FirstPage;
                    m_EmptyPages[i].PageLength += pages.PageLength;
                    m_InUsePages.Remove(pages);
                    block_found = true;
                    break;
                }
                if (m_EmptyPages[i].FollowingPage == pages.FirstPage)
                {
                    m_EmptyPages[i].PageLength += pages.PageLength;
                    m_InUsePages.Remove(pages);
                    block_found = true;
                    break;
                }
            }
            // otherwise add a new free block of pages.
            if (!block_found)
            {
                m_EmptyPages.Add(new PagesAvailable(pages.FirstPage, pages.PageLength));
                m_InUsePages.Remove(pages);
            }

            if (m_ContiguousMonitorCount++ >= 32)
                MergeContiguousEmptyBlocks();
        }
Example #2
0
        public Bookmark RequestContiguousFreePages(int count)
        {
            for (int i = 0; i < m_EmptyPages.Count; i++)
            {
                if (m_EmptyPages[i].PageLength >= count)
                {
                    PagesAvailable available = m_EmptyPages[i];
                    PagesInUse new_pages = new PagesInUse(available.FirstPage, m_Offset, count, InternalEventPagesReleased);
                    available.FirstPage += count;
                    available.PageLength -= count;
                    m_InUsePages.Add(new_pages);
                    return new_pages.GetBookmark();
                }
            }

            Logging.Fatal(string.Format("RequestContiguousFreePages failed with page count of {0}.", count));
            return null;
        }