When using System.IO.FileStream, I write 8 bytes, then seek to the start of the file, does the 8 byt

D

DR

When using System.IO.FileStream, I write 8 bytes, then seek to the start of
the file, does the 8 bytes get flushed on seek and the buffer become a
readbuffer at that point instead of being a write buffer?
 
M

Michael Nemtsev [MVP]

Hello dr,

as I remember if u don't flush and reopen it again you can't seek it

---
WBR,
Michael Nemtsev [Microsoft MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


d> When using System.IO.FileStream, I write 8 bytes, then seek to the
d> start of the file, does the 8 bytes get flushed on seek and the
d> buffer become a readbuffer at that point instead of being a write
d> buffer?
d>
 
A

Anthony Jones

Patrice said:
Well, don't you have thought you could just try ?

My findongs are quite as expected that is :
- reading works (this is a buffer, reading a buffer you have written to is
not really a problem)
- content is not flushed on disk when seeking the origin. You can always
flush explictely if needed (but this is not needed to be able to read the
buffer)


My findings are different. Opening a file for read/write with shared read
causes will cause any written data to be flushed when Seek is used.
However an exclusive lock may cause the underlying OS API to make different
choices.

My adviced to DR (who has liberally multiposted this Q) is:-
If you are worried that you might be overwritting data that
hasn't been stored yet then don't be.

If you want to make sure that data is persisted before doing other things
then you should explicitly flush. Just because seek appears to flush in a
the above case may simply be a result of specific OS decisions. In other
circumstances the underlying OS (on windows FileStream is a fairly
transparent wrapper on the Win APIs for these operations) may make other
choices.
<<

Which I posted in the dotnet.general group.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top