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

ReleasePage() public method

Releases a block back to the pool so it can be re-allocated.
public ReleasePage ( int index ) : void
index int the index identifier of the block
return void
        public void ReleasePage(int index)
        {
            if (index > 0)
            {
                index--;
                lock (m_syncRoot)
                {
                    if (m_disposed)
                        throw new ObjectDisposedException(GetType().FullName);

                    if (m_isPageFree.TrySetBit(index))
                    {
                        //IntPtr page = GetPageAddress(index);
                        //Memory.Clear(page,PageSize);
                        m_usedPageCount--;
                        return;
                    }
                }
            }

            Log.Publish(MessageLevel.Warning, MessageFlags.BugReport, "A page has been released twice. Some code somewhere could create memory corruption");
            throw new Exception("Cannot have duplicate calls to release pages.");
        }

Usage Example

Example #1
0
 /// <summary>
 /// Releases the page back to the buffer pool for reallocation.
 /// </summary>
 /// <param name="pageIndex">A value of zero or less will return silently</param>
 /// <remarks>The page released will not be initialized.
 /// Releasing a page is on the honor system.
 /// Rereferencing a released page will most certainly cause
 /// unexpected crashing or data corruption or any other unexplained behavior.
 /// </remarks>
 public void ReleasePage(int pageIndex)
 {
     m_pageList.ReleasePage(pageIndex);
     m_releasePageVersion++;
 }