ç的Windows缓冲区大小 [英] C Windows buffer size

查看:159
本文介绍了ç的Windows缓冲区大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在窗户可以说我使用了的recv 函数从套接字接收数据。
我很好奇,有多大将最佳的缓冲区呢?我可以使它 1024 字节或者我可以使它 51200 字节或更大。我不知道哪一个会获得更好的性能。

这不仅适用于的recv 的功能,可以说即时阅读了大量的文本文件,做我想做一个非常大的缓冲区或较小的缓冲区<? / p>

解决方案

操作系统执行自己的缓冲,所以你的缓冲区的大小并不重要。性能损失在于函数调用:一个1字节的缓冲区将是低效的,因为它需要太多的调用的recv()。过大的缓冲区只是浪费空间。

最优规模将会像你预期或能够在一个单一的的recv()调用的过程,下限数据的两倍约1或2个TCP帧

我个人使用4KB缓冲区,但是这是我自己的preference,这在很大程度上取决于我写的应用程序。

In windows lets say i'm using the recv function to receive data from a socket. I'm curious how big would an optimal buffer be? I could make it 1024 bytes or I could make it 51200 bytes, or bigger. I'm wondering which one would be better for performance.

This doesn't only apply to the recv function, lets say im reading a large text file, do i want a very large buffer, or a smaller buffer?

解决方案

THe operating system performs its own buffering, so the size of your buffer does not really matter. the performance penalty lies in the function call: a 1 byte buffer will be inefficient because it will require too much calls to recv(). a buffer too big is just a waste of space.

an optimal size will be something like twice the size of the data you expect to receive or are able to process in a single recv() call, with a lower limit of approximately 1 or 2 tcp frame.

i personally use a 4KB buffer, but that's my own preference, and it depends largely on the application i am writing.

这篇关于ç的Windows缓冲区大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆