Re: write to file with no used of buffered-IO functions
"Alex Blekhman" <xfkt@oohay.moc> wrote in message
news:%23aLkQmEnHHA.4624@TK2MSFTNGP04.phx.gbl...
Eitan M wrote:
... and also do after lseek :
write command.
I suppose that the above write at the position I gaved,
and hence all the bytes till the position I gaved are filled (with zeros
...)
Yes, you're correct. Actually, `_chsize' that I noticed is not an optimal
choice here, since it uses `WriteFile' in a loop in order to extend file
length. If you're goal is to grow a file with as few function calls as
possible, then you should use PSDK functions:
HANDLE h = CreateFile(
_T("C:\\Temp\\test.bin"),
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
SetFilePointer(h, 100000L, NULL, FILE_BEGIN);
SetEndOfFile(h);
However, that won't overwrite existing content... when the file is
truncated, you may very well be allocated different blocks, leaving the
original data intact on the disk.
I think MapViewOfFile + ZeroMemory may provide a better overwrite guarantee
(I'm not knowledgable enough to know if you can turn off buffering, but I
assume so).
Alex