FWRITE和写大小的性能 [英] Performance of fwrite and write size

查看:702
本文介绍了FWRITE和写大小的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了大量的数值2维数组为二进制文件(最终大小〜75 MB)。

I'm writing out a large numerical 2 dimensional array to a binary file (final size ~75 MB).

我在Linux系统上这样做。首先,有没有更好的方法或系统调用不是FWRITE对方尽可能快地写入文件?

I'm doing this on a linux system. First, is there a better method or syscall other than fwrite to write the file as fast as possible?

第二,如果我要使用FWRITE,那么我应该只是写了整个文件作为1个连续行?

Second, if I should use fwrite, then should I just write the whole file as 1 contiguous line?

fwrite( buf, sizeof(float), 6700*6700, fp );

,或写为一系列块

or write it as a series of chunks

fwrite( buf, sizeof(float), 8192, fp );
fwrite( *(buf+8192), sizeof(float), 8192, fp );
....

如果我应该块写的,每块应该多大?

If I should chunk the writing, how big should each chunk be?

推荐答案

只需使用FWRITE(没有必要去低级别的系统调用),并做它作为一个块。较低级别的系统调用将弄清楚如何缓存和分割的写命令是最好的。我从来没有能够击败这样的事情FWRITE的表现 - 大顺序写入

Just use fwrite (no need to go lower level syscalls) and do it as one chunk. The lower level syscalls will figure out how to buffer and split up that write command the best. I've never been able to beat fwrite's performance on things like this - large sequential writes.

这篇关于FWRITE和写大小的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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