473,320 Members | 1,825 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,320 software developers and data experts.

FlieStream SetLength()

I notice that when I call the SetLength() on a FileStream the data is saved
to the file. I thought that the only way to save data to the file was by
either calling Flush() or Close(). I looked at the documentation and it does
not say anything about the data being saved when calling this method (at
leas I didn't see it), is this normal behavior?

Thanks.
Nov 16 '05 #1
3 2640
Rene <no****@nospam.nospam> wrote:
I notice that when I call the SetLength() on a FileStream the data is
saved to the file. I thought that the only way to save data to the
file was by either calling Flush() or Close(). I looked at the
documentation and it does not say anything about the data being saved
when calling this method (at leas I didn't see it), is this normal
behavior?


Yes. There's nothing to say when data *won't* be saved to the file -
only that Flush and Close *will* make sure that all the data is saved.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Thanks, now if you don't mind I would like to take advantage of you kindness
and would like to ask you another little question.

According to the documentation, the Flush() method is supposed to clear the
buffer, but when I examine the buffer (_buffer) using the Watch window,
nothing happens to the data after it method is called! Isn't it supposed to
clear everything to zeros? or at least set the Length of the File stream to
zero?

Thanks.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Rene <no****@nospam.nospam> wrote:
I notice that when I call the SetLength() on a FileStream the data is
saved to the file. I thought that the only way to save data to the
file was by either calling Flush() or Close(). I looked at the
documentation and it does not say anything about the data being saved
when calling this method (at leas I didn't see it), is this normal
behavior?


Yes. There's nothing to say when data *won't* be saved to the file -
only that Flush and Close *will* make sure that all the data is saved.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Never mind, I think I got it. If I flush() the data on the _buffer variable
remain the same (no point on waiting CPU cycles to turn the values to zero I
guess) but if I write to the buffer after the flush() the new data is not
appended at the end of the last writhe, it starts from index zero.

Man, I can't believe I have spent hours looking at this stupid thing and I
still don't fully understand everything about it, agggggggggggggggggg!

"Rene" <no****@nospam.nospam> wrote in message
news:u0**************@TK2MSFTNGP11.phx.gbl...
Thanks, now if you don't mind I would like to take advantage of you
kindness and would like to ask you another little question.

According to the documentation, the Flush() method is supposed to clear
the buffer, but when I examine the buffer (_buffer) using the Watch
window, nothing happens to the data after it method is called! Isn't it
supposed to clear everything to zeros? or at least set the Length of the
File stream to zero?

Thanks.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Rene <no****@nospam.nospam> wrote:
I notice that when I call the SetLength() on a FileStream the data is
saved to the file. I thought that the only way to save data to the
file was by either calling Flush() or Close(). I looked at the
documentation and it does not say anything about the data being saved
when calling this method (at leas I didn't see it), is this normal
behavior?


Yes. There's nothing to say when data *won't* be saved to the file -
only that Flush and Close *will* make sure that all the data is saved.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #4

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

Similar topics

3
by: Anon | last post by:
I made this class to encrypt my DataSet before saving it to disk. So, first in the main program I write the DataSet to XML in a MemoryStream. I pass this stream to the E_File sub, which encrypts...
13
by: Don | last post by:
When I run the following code, the MemoryStream's Position is always set to 762 instead of 0, which is what I would expect: Dim bmp As Image Dim ms As MemoryStream bmp = New...
9
by: Tim_Mac | last post by:
hi, i'm not sure if i have chosen the best approach, but it seemed quite good to me. i have a collection class, containing business objects. the collection class is static and remains in-memory...
12
by: rodneys | last post by:
Hi, please take a look to this sample code: class MyClass { private: static int length ; public: static void setLength(int newLength) ; void do() ;
72
by: Jacob | last post by:
I have compiled a set og unit testing recommendations based on my own experience on the concept. Feedback and suggestions for improvements are appreciated: ...
6
by: teddarr | last post by:
I am working on this assignment once again. I've already had a fair amount of help from this site but I've combed the book and my notes and I still don't have a fix (or a clue). I have a program...
7
by: teddarr | last post by:
I have an assignment I've been working on for a few days now. I need some help with the last detail. The program is supposed to create 5 objects with varying floating-point parameter lists. The...
8
by: Hypnotik | last post by:
So I'm working on a program. Base class is a polygon (which has an unknown number of sides), with derived classes for rectangle and triangle which inherit from the polygon, and square which inherits...
16
by: drwyness | last post by:
Hello, Please help with the following problem it is causing me some headaches. The following javascript code is designed to fill in text boxes with numbers on an online game (tribalwars). It...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.