FileStream Speed issue

G

Guest

Yello,

Quick Q:
What is the fastest way of getting data from a file?
Does the though put of the file increase if I collect
a great big chunk of it? Eg say 6meg? or does that
even help?

Does a bufferedstream work better if I am just going
to open a file and read it?

All I am doing, is opening the file stream,
collecting enough data for a "packet" of data,
parcing it, then going for another packet.
I though maybe if I collect a chunk of memory
from the HD, the speed may improve?

Thanks in advance.
 
N

Nicholas Paldino [.NET/C# MVP]

TheMadHatter,

This is one of those things where you have to fine tune your code in
response to regular conditions.

I don't think a bufferedstream will work here because getting the bytes
is going to be a quick operation.

What you have to remember is that while you might decrease the number of
file operations by reading larger chunks from the file system, you have to
weigh that against the cost of memory allocation, which in large chunks, can
be more detrimental than the hit you would take reading from the file
system.

Hope this helps.
 
J

Jon Skeet [C# MVP]

TheMadHatter said:
Quick Q:
What is the fastest way of getting data from a file?
Does the though put of the file increase if I collect
a great big chunk of it? Eg say 6meg? or does that
even help?

In my experience it helps a very small amount (and only in some tests).
I would suggest a buffer size of about 16 or 32K usually. That way it's
definitely not on the large object heap, but can store a fair chunk of
data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top