由于需要实时存储大量的数据。我以CMemFile的形式开辟了两个内存缓冲区(20K大小),一旦写满后启动一个线程写盘。但发现最终的文件中有一些数据出错,why?
我的代码如下:
CStdioFile f( pFileName, CFile::modeCreate | CFile::modeWrite CStdioFile|CFile::typeText);
pMemFile->SeekToBegin();
BYTE *pMem=pMemFile->Detach();
f.Write(pMem,Length);
f.Close();
free(pMem);

解决方案 »

  1.   

    Calling this function also closes the CMemFile. You can reattach the memory block to CMemFile by calling Attach. If you want to reattach the file and use the data in it, you should call CFile::GetLength to get the length of the file before calling Detach. Note that if you attach a memory block to CMemFile so that you can use its data (nGrowBytes == 0), then you won't be able to grow the memory file.
      

  2.   


    我在pMemFile->Detach()前使用了Length=pMemFile->GetLength(),还是不行。奇怪的是,出现在最终的数据文件中间,会有部分数据是对的,Why?
    谢谢!