Article View: comp.os.msdos.programmer
Article #7915Re: open vs fopen?
From: Kazimir Kylheku
Date: Sat, 10 Feb 1996 05:32
Date: Sat, 10 Feb 1996 05:32
34 lines
1850 bytes
1850 bytes
In article <4f8qf1$h3b@ssbunews.ih.att.com>,
Harold E. Bamford <bamford@marconi.ih.att.com> wrote:
>In article <uEYFxc9nX8WX083yn@mbnet.mb.ca>,
>Nathan T. Wild <natewild@mbnet.mb.ca> wrote:
>
>>In C, why would one use open and DOS int handles rather than fopen and
>>stdio file handles?
>>
>>Is there some speed advantage or differnet functionality?
>
>open() is for raw I/O. You use read(), write(), lseek(), ltell()
>
>fopen() is for buffered I/O. You can use fread(), fscanf(), fgets(),
>getchar(), putchar, fprint(), fwrite(), fseek(), ftell(), etc.
False. Both are buffered. The latter does an extra copy.
The justification for the extra buffering in the latter is that you can pump
data in smaller chunks _without_ causing needless context switches to the
kernel.
Calling fread() a byte at a time is much more efficient than calling read() a
byte at a time, because each call to read() causes a call to the kernel.
However, calling read() several kilobytes at a time is more efficient than
fread(), because it dispenses with an extra level of overhead.
>For certain applications, you can get away without buffering. But
>often it is easier to do the programming if you don't have to worry
>about unneeded system calls and buffering gives you that.
^^^^^^^^^^^^^^^^^^^^^
Ah, now you are hitting much closer to the target!
--
Technical Details
Message-ID:
<4fhal0INN7vm@keats.ugrad.cs.ubc.ca>Path:
arc1-ca.pugleaf.net!keats.ugrad.cs.ubc.ca!not-for-mailReferences:
<uEYFxc9nX8WX083yn@mbnet.mb.ca> <4f8qf1$h3b@ssbunews.ih.att.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!keats.ugrad.cs.ubc.ca!not-for-mail From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) Newsgroups: comp.os.msdos.programmer,comp.lang.c Subject: Re: open vs fopen? Date: 9 Feb 1996 21:32:16 -0800 Organization: Computer Science, University of B.C., Vancouver, B.C., Canada Distribution: na Message-ID: <4fhal0INN7vm@keats.ugrad.cs.ubc.ca> References: <uEYFxc9nX8WX083yn@mbnet.mb.ca> <4f8qf1$h3b@ssbunews.ih.att.com> NNTP-Posting-Host: keats.ugrad.cs.ubc.ca