Re: write to file with no used of buffered-IO functions
- From: "Ben Voigt" <rbv@xxxxxxxxxxxxx>
- Date: Tue, 22 May 2007 08:32:49 -0500
"Alex Blekhman" <xfkt@xxxxxxxxx> wrote in message
news:%23aLkQmEnHHA.4624@xxxxxxxxxxxxxxxxxxxxxxx
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
.
- Follow-Ups:
- Re: write to file with no used of buffered-IO functions
- From: Alex Blekhman
- Re: write to file with no used of buffered-IO functions
- References:
- write to file with no used of buffered-IO functions
- From: Eitan M
- Re: write to file with no used of buffered-IO functions
- From: Alex Blekhman
- Re: write to file with no used of buffered-IO functions
- From: Eitan M
- Re: write to file with no used of buffered-IO functions
- From: Eitan M
- Re: write to file with no used of buffered-IO functions
- From: Alex Blekhman
- write to file with no used of buffered-IO functions
- Prev by Date: Re: delete vs delete[]
- Next by Date: Re: how to access
- Previous by thread: Re: write to file with no used of buffered-IO functions
- Next by thread: Re: write to file with no used of buffered-IO functions
- Index(es):
Relevant Pages
|