如何估计从 NetworkStream 读取的字节数组/缓冲区的大小?
int bufferSize = 8192;
Byte[] buffer = new Byte[bufferSize];
我需要从 NetworkStream 中读取数据,该网络流将以高速率连续输入数据流。我想知道
- 设置
bufferSize
值的基础是什么? - 是否有一个标准的“安全”值 可以选择,无论 环境?
- 它是否也随流而变化 我正在尝试读取 (文件流/网络流/..)?
请将性能作为评估的重点。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
优化性能只有一种可靠的方法:测量、测量、测量。
我见过 1024、4096 或 8192 用作从互联网下载文件的缓冲区大小,但我没有注意到使用任何一个有任何显着差异。
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.