本文整理汇总了C#中IoSession.TryGetSubPage方法的典型用法代码示例。如果您正苦于以下问题:C# IoSession.TryGetSubPage方法的具体用法?C# IoSession.TryGetSubPage怎么用?C# IoSession.TryGetSubPage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IoSession
的用法示例。
在下文中一共展示了IoSession.TryGetSubPage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CommitChanges
/// <summary>
/// Executes a commit of data. This will flush the data to the disk use the provided header data to properly
/// execute this function.
/// </summary>
/// <param name="header"></param>
public void CommitChanges(FileHeaderBlock header)
{
using (var pageLock = new IoSession(this, m_pageReplacementAlgorithm))
{
//Determine how much committed data to write
long lengthOfAllData = (header.LastAllocatedBlock + 1) * (long)m_fileStructureBlockSize;
long copyLength = lengthOfAllData - m_lengthOfCommittedData;
//Write the uncommitted data.
m_queue.Write(m_lengthOfCommittedData, m_writeBuffer, copyLength, waitForWriteToDisk: true);
byte[] bytes = header.GetBytes();
if (header.HeaderBlockCount == 10)
{
//Update the new header to position 0, position 1, and one of position 2-9
m_queue.WriteRaw(0, bytes, m_fileStructureBlockSize);
m_queue.WriteRaw(m_fileStructureBlockSize, bytes, m_fileStructureBlockSize);
m_queue.WriteRaw(m_fileStructureBlockSize * ((header.SnapshotSequenceNumber & 7) + 2), bytes, m_fileStructureBlockSize);
}
else
{
for (int x = 0; x < header.HeaderBlockCount; x++)
{
m_queue.WriteRaw(x * m_fileStructureBlockSize, bytes, m_fileStructureBlockSize);
}
}
m_queue.FlushFileBuffers();
long startPos;
//Copy recently committed data to the buffer pool
if ((m_lengthOfCommittedData & (m_diskBlockSize - 1)) != 0) //Only if there is a split page.
{
startPos = m_lengthOfCommittedData & (~(long)(m_diskBlockSize - 1));
//Finish filling up the split page in the buffer.
IntPtr ptrDest;
if (pageLock.TryGetSubPage(startPos, out ptrDest))
{
int length;
IntPtr ptrSrc;
m_writeBuffer.ReadBlock(m_lengthOfCommittedData, out ptrSrc, out length);
Footer.WriteChecksumResultsToFooter(ptrSrc, m_fileStructureBlockSize, length);
ptrDest += (m_diskBlockSize - length);
Memory.Copy(ptrSrc, ptrDest, length);
}
startPos += m_diskBlockSize;
}
else
{
startPos = m_lengthOfCommittedData;
}
while (startPos < lengthOfAllData)
{
//If the address doesn't exist in the current list. Read it from the disk.
int poolPageIndex;
IntPtr poolAddress;
m_pool.AllocatePage(out poolPageIndex, out poolAddress);
m_writeBuffer.CopyTo(startPos, poolAddress, m_diskBlockSize);
Footer.WriteChecksumResultsToFooter(poolAddress, m_fileStructureBlockSize, m_diskBlockSize);
if (!m_pageReplacementAlgorithm.TryAddPage(startPos, poolAddress, poolPageIndex))
m_pool.ReleasePage(poolPageIndex);
startPos += m_diskBlockSize;
}
m_lengthOfCommittedData = lengthOfAllData;
}
ReleaseWriteBufferSpace();
}