如何估计从 NetworkStream 读取的字节数组/缓冲区的大小?

发布于 2024-10-08 02:25:27 字数 295 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

塔塔猫 2024-10-15 02:25:27

优化性能只有一种可靠的方法:测量、测量、测量。

我见过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文