473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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?

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?
Jul 29 '08 #1
4 1720
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
dWhen using System.IO.FileStream, I write 8 bytes, then seek to the
dstart of the file, does the 8 bytes get flushed on seek and the
dbuffer become a readbuffer at that point instead of being a write
dbuffer?
d>
Jul 29 '08 #2
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)

You may want to explain what you are trying to do...
"DR" <so*******************@yahoo.coma écrit dans le message de groupe de
discussion : OX**************@TK2MSFTNGP02.phx.gbl...
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?
Jul 29 '08 #3
"Patrice" <http://www.chez.com/scribe/wrote in message
news:02**********************************@microsof t.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
Jul 29 '08 #4
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.
Ah yes !! I always find weird those kind of questions that looks to come out
from thin air, I didn't caught he might want to flush if reading from
another application. It always looks like to me like a strange obession to
know the gory details from an academic point of view ;-)

Once again it just show it's generally better for an OP to explain what he's
trying to do so that one could help achieving this goal rather than to work
the other way round and see if how things behave will fit his needs...

--
Patrice


Jul 29 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Skwerl | last post by:
Hi guys. I've written code to embed an ICC profile in a TIFF image, and I think my IO operations are slowing things down. It is taking about a second to embed each tag in 7-meg TIFF files. ...
1
by: Markusek Peter | last post by:
Hi, I'm using MySQLDriverCS. I've got no problem to store BLOB into database, but I can't get it back(save to file). Problem is with DataTable(returns string:( ) My code: -- DataTable dt = new...
13
by: Rick | last post by:
The following code will enter an infinate loop when in ReadChars. I can only make it happen when reading a Stream and with this particular XML. If I use the ReadInnerXml call rather than my own...
0
by: Janusz Nykiel | last post by:
I've stumbled upon unexpected behavior of the .NET 2.0 System.Xml.XmlWriter class when using it to write data to a binary stream (System.IO.Stream). If the amount of data is less than a certain...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
0
by: DR | last post by:
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...
0
by: Mark Salsbery [MVP] | last post by:
"DR" <softwareengineer98037@yahoo.comwrote in message news:Op0NyzR8IHA.1200@TK2MSFTNGP04.phx.gbl... If the filestream is opened for write access then it still keeps its write access. If you...
0
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
I have a web site under .NET 2.0 that renders videos using the Silverlight media player. The web page looks like this: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="video2.aspx.cs"...
13
by: =?Utf-8?B?Um9nZXIgTWFydGlu?= | last post by:
This is a follow-up to my post "Silverlight video doesn't work when file is streamed from handler in ASP.net" at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.