fwrite输出效率不高(快)? [英] fwrite output is not efficient (fast) ?

查看:702
本文介绍了fwrite输出效率不高(快)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




最近一些C程序员告诉我,使用fwrite / fopen函数

效率不高,因为他们对文件的输出是

实际上是缓冲而且迟到了。这是真的吗?


问候,


... ab

Hi,

recently some C programmer told me that using fwrite/fopen functions
are not efficient because the output that they do to the file is
actually buffered and gets late in writing. Is that true?

regards,

...ab

推荐答案

Abubakar< ab ******* @ gmail.comwrote:
Abubakar <ab*******@gmail.comwrote:

最近一些C程序员告诉我使用fwrite / fopen函数

效率不高,因为他们对文件做的输出实际上是缓冲的,并且写得很晚。
recently some C programmer told me that using fwrite/fopen functions
are not efficient because the output that they do to the file is
actually buffered and gets late in writing.



这很可能不是C程序员,而是一个GNU-almost-POSIX-

with a-bit-of- C-thrown-in-for-appearance'的程序员。

That most probably wasn''t a C programmer, but a GNU-almost-POSIX-
with-a-bit-of-C-thrown-in-for-appearance''s-sake programmer.


这是真的吗?
Is that true?



如上所述,事实并非如此。对于某些系统而言,某些情况可能属于某种情况;但是你应该永远不用担心优化,直到你需要,并且不要只想到你。


Richard

As phrased, it is not true. It may be true for some systems, under some
circumstances; but you should never worry about optimisation until you
_know_ that you have to, and don''t just think you might.

Richard


>最近一些C程序员告诉我使用fwrite / fopen函数
>recently some C programmer told me that using fwrite/fopen functions

>效率不高因为输出那个他们对文件做的实际上是缓冲的并且写得太迟了。真的吗?
>are not efficient because the output that they do to the file is
actually buffered and gets late in writing. Is that true?



对于某些我已经进行过基准测试的程序(基本上是使用单字符读取来执行
磁盘到磁盘文件的复制) )和写()

调用复制文件会占用大量的CPU时间。切换到

getc()/ putc()/ fopen()调用将用于复制给定

文件的CPU减少了10倍,并将挂钟时间减少到完成复制

文件大约10%。在这种特殊情况下,缓冲

有助于加快速度。

For some programs I have benchmarked (which were essentially doing
disk-to-disk file copies), using single-character read() and write()
calls to copy files chews up a lot of CPU time. Switching to
getc()/putc()/fopen() calls reduced the CPU used to copy a given
file by a factor of 10 and the wall clock time to finish copying
the file by about 10%. In this particular situation, buffering
helped speed things up a lot.


Abubakar说:
Abubakar said:




最近一些C程序员告诉我,使用fwrite / fopen函数

效率不高,因为他们输出的是文件是

实际缓冲并且写得迟到了。真的吗?
Hi,

recently some C programmer told me that using fwrite/fopen functions
are not efficient because the output that they do to the file is
actually buffered and gets late in writing. Is that true?



我建议你问你的朋友:


1)为什么他认为fopen会输出任何文件;

2)为什么他认为文件的缓冲状态完全取决于fopen

或fwrite;

3)他认为setbuf和setvbuf是什么for;

4)他的意思是高效。


您可能会发现这些问题的答案很有启发性。在另一方面,你可能不会。


1),2),和3)所有人都应该让他踩踏板,4)应该至少

让他停下来思考这里真正的问题。


-

Richard Heathfield< http:/ /www.cpax.org.uk>

电子邮件:-http:// www。 + rjh @

谷歌用户:< http://www.cpax.org.uk/prg/writings/googly.php>

Usenet是一个奇怪的放置" - dmr 1999年7月29日

I suggest you ask your friend:

1) why he thinks fopen outputs anything at all to a file;
2) why he thinks the buffering status of a file depends entirely on fopen
or fwrite;
3) what he thinks setbuf and setvbuf are for;
4) what he means by "efficient".

You may well find the answers to those questions illuminating. On the other
hand, you might not.

1), 2), and 3) should all send him back-pedalling, and 4) should at least
make him stop and think about the real issues here.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999


这篇关于fwrite输出效率不高(快)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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