Performance of fwrite and write size

后端 未结 5 1521
小蘑菇
小蘑菇 2020-12-15 12:29

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

I\'m doing this on a linux system. First, is there a better method or s

5条回答
  •  轮回少年
    2020-12-15 12:56

    You can find the source of fwrite in

    http://sourceware.org/git/?p=glibc.git;a=blob;f=libio/iofwrite.c;hb=HEAD

    As you can see, this in turn calls IO_sputn, which eventually ends up in

    http://sourceware.org/git/?p=glibc.git;a=blob;f=libio/fileops.c;hb=HEAD

    (specifically, _IO_new_file_xsputn). As you can see, this always goes through the stdio buffer.

    So I would advise against using stdio; writing directly using write(2) will bypass this extra copy.

提交回复
热议问题