Chinaunix

标题: 几年没有写C了,在C中如何提高IO中写的速度,一般有什么技巧? [打印本页]

作者: loufangxin    时间: 2005-03-04 11:46
标题: 几年没有写C了,在C中如何提高IO中写的速度,一般有什么技巧?
我面程序中会用到fprintf和fwrite交叉调用,经调试,发现写得很慢,一般只能写入4M/s(笔忘本上),不知有没有办法提高?
作者: ilike911    时间: 2005-03-04 12:31
标题: 几年没有写C了,在C中如何提高IO中写的速度,一般有什么技巧?
#include <stdio.h>;
  int setvbuf( FILE *stream, char *buffer, int mode, size_t size );



The function setvbuf() sets the buffer for stream to be buffer, with a size of size. mode can be:

_IOFBF, which indicates full buffering
_IOLBF, which means line buffering
_IONBF, which means no buffering

if you use linux, should also to check hd wich hdparm to confirm it's in 32bit i/o.
作者: loufangxin    时间: 2005-03-04 13:30
标题: 几年没有写C了,在C中如何提高IO中写的速度,一般有什么技巧?
Thank ilike911.
作者: loufangxin    时间: 2005-03-05 10:42
标题: 几年没有写C了,在C中如何提高IO中写的速度,一般有什么技巧?
After I setvbuf to a 256k buf, the IO write performance got 50% improvement, when I try to setvbuf on IO read, it did not help.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2