Is Lof accurate before calling FlushFileBuffers?
Is Lof accurate before calling FlushFileBuffers?
It I load a file and then write to it, is the result from Lof guaranteed to be correct (versus FileSize) if I don't call FlushFileBuffers first?
Re: Is Lof accurate before calling FlushFileBuffers?
I was about to say yes here but then realized I too have no idea if Lof is updated along with the writebuffer or not... *scratches head*
- DoubleDutch
- Addict
- Posts: 3219
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
Re: Is Lof accurate before calling FlushFileBuffers?
Good question. I would think that until closefile() it wouldn't be, but don't know for sure.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system
-
- Enthusiast
- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: Is Lof accurate before calling FlushFileBuffers?
Try it! :roll:
Re: Is Lof accurate before calling FlushFileBuffers?
In Linux, if you compile
and do an strace for if, you obtain
I see that an fstat64 function is called everytime you call a Lof(), so I would presume that the answer would be yes.
But what if the filesystem management, in certain occasions, holds the actual filewriting... That the new file operation entails flushing would be proper engineering IMHO.
I would also test on Win and Mac.
Interesting question.
Code: Select all
If OpenFile(0,"/tmp/testlof")
PrintN( Str(Lof(0)) )
WriteStringN(0,"123123")
PrintN( Str(Lof(0)) )
WriteStringN(0,Str(Random(99999999)))
PrintN( Str(Lof(0)) )
CloseFile(0)
EndIf
Code: Select all
[...]
open("/tmp/testlof", O_RDWR) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=4, ...}) = 0
fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x731000
write(1, "4\n", 24
) = 2
fstat64(3, {st_mode=S_IFREG|0644, st_size=4, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x64a000
_llseek(3, 0, [0], SEEK_CUR) = 0
write(3, "123123\n", 7) = 7
fstat64(3, {st_mode=S_IFREG|0644, st_size=7, ...}) = 0
write(1, "7\n", 27
) = 2
gettimeofday({1265539169, 589739}, NULL) = 0
write(3, "36040943\n", 9) = 9
fstat64(3, {st_mode=S_IFREG|0644, st_size=16, ...}) = 0
write(1, "16\n", 316
) = 3
close(3) = 0
[...]
But what if the filesystem management, in certain occasions, holds the actual filewriting... That the new file operation entails flushing would be proper engineering IMHO.
I would also test on Win and Mac.
Interesting question.
Re: Is Lof accurate before calling FlushFileBuffers?
@UserOfPure: I believe the point is not "will it happen now", but "will it always happen"
@Mistrel: in doubt, you thought about keeping track of filesize within the code (you are the one writing into the file afterall), did not you?
@Mistrel: in doubt, you thought about keeping track of filesize within the code (you are the one writing into the file afterall), did not you?
Re: Is Lof accurate before calling FlushFileBuffers?
Lof() calls FlushBuffers() if data is in the write buffer, so it will be correct.
quidquid Latine dictum sit altum videtur
- DoubleDutch
- Addict
- Posts: 3219
- Joined: Thu Aug 07, 2003 7:01 pm
- Location: United Kingdom
- Contact:
Re: Is Lof accurate before calling FlushFileBuffers?
Freak: you and Fred seem to have thought of everything!
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
https://reportcomplete.com <- School end of term reports system
Re: Is Lof accurate before calling FlushFileBuffers?
Thank you, freak. That's all I needed to know.