最佳缓冲区大小在C读取文件 [英] optimal buffer size for reading file in C

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

问题描述

我在使用函数用C来读取大文件。我只是想知道,如果它使什么缓冲区大小,我们不断在性能方面有什么区别。文件大小可能达到几十到GB的。

I have to read large files in C using read function. I was just wondering if it makes any difference what buffer size we keep in terms of performance. The file sizes may reach till tens of GB.

推荐答案

短版。结果
这取决于。在4096字节的x86缓冲区大小是一个良好的开端(一个的页面大小高级格式块大小)。

Short version.
It depends. On x86 buffer size of 4096 bytes is a good start (one page size and also Advanced Format block size).

更长的版本。结果
在UNIX这取决于内核,libc,文件系统,硬件等不仅对版本和编译选项还对运行时可调参数(如预读设置)。

Longer version.
In UNIX it depends on kernel, libc, filesystem, hardware, etc. Not only on versions and compilation options but also on run-time tunables(e.g read ahead setup).

DIY。结果
测试一下吧!请参见高级编程在UNIX环境 3.9章I / O效率的确定直接的方法最好读写缓冲器大小为一个特定的系统。

DIY.
Test it! See Advanced Programing in UNIX Environment Chapter 3.9 "I/O Efficiency" for straightforward way of determining the best read-write buffer size for one particular system.

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

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