开发者

How to estimate the size of byte array/buffer to read from NetworkStream?

开发者 https://www.devze.com 2023-01-31 10:08 出处:网络
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
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 bufferSize value?
  • Is there a standard "safe" value that can be chosen irrespective开发者_C百科 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消