FlieStream SetLength()

  • Thread starter Thread starter Rene
  • Start date Start date
R

Rene

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.
 
Rene said:
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.
 
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.
 
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 said:
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.
 
Back
Top