Should I Merge CFile::Write Operations?

  • Thread starter Thread starter chcw
  • Start date Start date
C

chcw

Guest
Hi,

I am using Visual C++ 2008. In the following codes, I need to write 10000000 bytes into a file:

CFile MyFile;

BYTE btValue;

If (MyFile.Open(strFileName, …))

{

For (int nIndex = 0; nIndex = 10000000; nIndex ++)

{

btValue = …; // Calculate the value to be written

MyFile.Write(&btValue, sizeof(btValue));

}

MyFile.Close();

}

Since I call MyFile.Write for 10000000 times, to improve the performance is it necessary to create a buffer(such as 64kb), then do as follows?

  1. Fill the buffer with the bytes to be written.
  2. When the buffer is full, write the buffer into MyFile.

I just wonder if CFile itself already has such a buffer mechanism or do I need to implement such a mechanism by myself?

Thanks

Continue reading...
 
Back
Top