int bufferSize = 8192;
Byte[] buffer = new Byte[bufferSize];
I need to read from a NetworkStream which would have a continuous flow of incoming data at a high rate. I wanted to know
- What should be the basis for setting the
bufferSizevalue? - Is there a standard “safe” value that
can be chosen irrespective of the
enviornment? - Should it also vary with the Stream
I’m trying to read from
(FileStream/NetworkStream/..)?
Please consider performance as the focus point for the estimation.
There is only one sure way to optimize performance: measure, measure, measure.
I’ve seen 1024, 4096 or 8192 used as buffer sizes for downloading files from the internet, and I haven’t noticed any significant difference using either one.