🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages Started by John Grabner Thu, 10 Jan 2008 04:27
winapi WriteFile single byte and buffering
#781
Author: John Grabner
Date: Thu, 10 Jan 2008 04:27
7 lines
1201 bytes
I am using WrtieFile to write a lot of single bytes to a file. Reading 
the documentation I cannot work out if I can have a buffered write and 
if so how do to do a buffered write.

Any one know the answer?

John.
Re: winapi WriteFile single byte and buffering
#782
Author: Asger Joergensen
Date: Thu, 10 Jan 2008 10:18
41 lines
1804 bytes
Hi John
 
 John Grabner says:
> I am using WrtieFile to write a lot of single bytes to a file. Reading 
> the documentation I cannot work out if I can have a buffered write and 
> if so how do to do a buffered write.

An idea:

class TBufferWrite
{
   AnsiString FBuffer;// or another type of buffer
   int FMaxBuffer, FBufferSize;
   HANDLE hFile;

   void __fastcall WriteBufferToFile(){FBufferSize = 0;};

public:

   __fastcall TBufferWrite()
   : FMaxBuffer(0)
   , hFile(0)
   , FBufferSize(0){}
   __fastcall ~TBufferWrite(){/*Close the File if open*/}

   bool __fastcall OpenFile(AnsiString FileName);
   bool __fastcall WriteFile(char aChar)
   {
      ++FBufferSize;
      FBuffer += aChar;
      if(FBufferSize >= FMaxBuffer)
         WriteBufferToFile();
   }
   void __fastcall CloseFile();
};

Code not tested in anyway..

Kind regards
Asger
Re: winapi WriteFile single byte and buffering
#786
Author: Ed Mulroy [TeamB]
Date: Thu, 10 Jan 2008 15:55
21 lines
1905 bytes
WriteFile is an operating system function and buffering for it is up to the 
OS.  Your only controls over buffering are from specifying one of 
FILE_FLAG_WRITE_THROUGH and FILE_FLAG_NO_BUFFERING in the call to 
CreateFile.  Both of them limit or remove the effects of buffering.  However 
without them, the OS still determines what buffering it will provide so is 
free to decide what size buffer to use including using no buffer.

Typically the writes to a hard drive are buffered for performance.

For more detail read the help file documentation on CreateFile.

.  Ed

> John Grabner wrote in message
> news:47859f0a$1@newsgroups.borland.com...
>
>I am using WrtieFile to write a lot of single bytes to a file. Reading the 
>documentation I cannot work out if I can have a buffered write and if so 
>how do to do a buffered write.
>
> Any one know the answer?
Re: winapi WriteFile single byte and buffering
#787
Author: Bob Gonder
Date: Thu, 10 Jan 2008 17:08
15 lines
1544 bytes
John Grabner wrote:

>I am using WrtieFile to write a lot of single bytes to a file. Reading 
>the documentation I cannot work out if I can have a buffered write and 
>if so how do to do a buffered write.

I believe Windows defaults to buffered writes.
You can turn +off+ buffered writes with these
two flags when you use CreateFile():
FILE_FLAG_WRITE_THROUGH
FILE_FLAG_NO_BUFFERING
So, in your case, make sure they are off.

In addition, you might want to turn on 
FILE_FLAG_SEQUENTIAL_SCAN
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads