Re: StreamReader.ReadToEnd



And in terms of speed, is StreamReader.ReadToEnd() or reading byte by
byte yourself (and handling the buffering yourself) faster?


Unless Microsoft did a really botched up job of implementing ReadToEnd I'd say that by default the implementation of ReadToEnd will be faster than reading byte by byte.

However, if your goal is to read the rest of the file and process it then it depends:

with your buffering solution, would you:

- fill the buffer, process it, then throw it away or reuse it?
- fill the buffer, then keep it and allocate a new buffer for the rest?

the difference would be if you were to process a really big file, larger than your amount of available memory. With .ReadToEnd, you might end up swapping memory blocks to disk, which is costly. If you process the file a buffer at a time, you might not need to as the size of the file would be irrelevant as you only keep a buffers worth in memory anyway.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:lasse@xxxxxxxxxxx
PGP KeyID: 0x2A42A1C2


.



Relevant Pages

  • Re: Read large text files
    ... i have tried to read files about 100M,but failed,out of memory error ... the buffer size is not enough,how do predict the buffer size in ... If so, ReadToEnd is probably okay. ...
    (microsoft.public.dotnet.framework)
  • Re: String Builder & String, whats the difference ?
    ... Odd that Microsoft doesn't recommend it that way... ... buffer is how it avoids re-allocating Memory). ... small amount of work with a string, it may indeed more efficient NOT to use ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: String Builder & String, whats the difference ?
    ... Odd that Microsoft doesn't recommend it that way... ... buffer is how it avoids re-allocating Memory). ... small amount of work with a string, it may indeed more efficient NOT to use ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Discovering variable types...
    ... >- but I suppose MS expect us to use wrappers ... memory allocations for your variables from disk as well. ... >They most certainly are of fixed size, changing the size of a String ... >>me to keep buffer size and current postion right in the memory block. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Discovering variable types...
    ... >memory it points to is on the heap. ... sequentially reading data, if one is randomly reading records, then a ... >project is what's prompting me to improve disk access. ... from a memory buffer I can do it in about a second. ...
    (comp.lang.pascal.delphi.misc)