Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   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? (http://www.velocityreviews.com/forums/t628033-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.html)

DR 07-29-2008 01:37 AM

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?
 
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?



Michael Nemtsev [MVP] 07-29-2008 05:10 AM

Re: 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?
 
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>



Anthony Jones 07-29-2008 09:50 AM

Re: 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?
 
"Patrice" <http://www.chez.com/scribe/> wrote in message
news:020D9BDA-BB88-4EE4-B8D8-911A9E122C54@microsoft.com...
> 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.


--
Anthony Jones - MVP ASP/ASP.NET




All times are GMT. The time now is 02:06 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.