Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > read vs fread

Reply
Thread Tools

read vs fread

 
 
Patrice Kadionik
Guest
Posts: n/a
 
      02-24-2005
Hi all,

I want to make a brief comparison between read() and fread() (under a
Linux OS).

1. Family read and Co: open, close, read, write, ioctl...
2. Family fread and Co: fopen, fclose, fread, swrite, fcntl...


Family read and Co:
- are syscalls.
- are not formatted IO : we have a non formatted byte stream.
- don't use the Linux buffer cache.
- generally used for accessing character devices.


Family fread and Co:
- are functions of the standard IO libc (glibc).
- use an internal buffer (in their coding)
- are formatted IO (with the "%.." parameter) for some of them.
- use always the Linux buffer cache.
- generally used for accessing bloc devices.

When I'm opening an ordinary file on a HD (bloc device), I'm always
using the buffer cache with open or fopen. In case of fopen, I'm using
in addition an internal buffer when I'm doing a fread or fwrite for
speeding HD access.
When I'm opening an character device, I'm not using the buffer cache.
Open and Co are generally used here.

Is is OK?
Some points I've forgotten?

Thank you for your response;
Pat.
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      02-24-2005
Patrice Kadionik <(E-Mail Removed)> writes:

> I want to make a brief comparison between read() and fread() (under a
> Linux OS).


This is not the place to do it. Try a Linux programming
newsgroup.
--
Ben Pfaff
email: http://www.velocityreviews.com/forums/(E-Mail Removed)
web: http://benpfaff.org
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      02-24-2005
Patrice Kadionik wrote:

> Hi all,
>
> I want to make a brief comparison between read() and fread() (under a
> Linux OS).
>
> 1. Family read and Co: open, close, read, write, ioctl...
> 2. Family fread and Co: fopen, fclose, fread, swrite, fcntl...
>
>
> Family read and Co:
> - are syscalls.
> - are not formatted IO : we have a non formatted byte stream.
> - don't use the Linux buffer cache.
> - generally used for accessing character devices.
>
>
> Family fread and Co:
> - are functions of the standard IO libc (glibc).
> - use an internal buffer (in their coding)
> - are formatted IO (with the "%.." parameter) for some of them.
> - use always the Linux buffer cache.
> - generally used for accessing bloc devices.
>
> When I'm opening an ordinary file on a HD (bloc device), I'm always
> using the buffer cache with open or fopen. In case of fopen, I'm using
> in addition an internal buffer when I'm doing a fread or fwrite for
> speeding HD access.
> When I'm opening an character device, I'm not using the buffer cache.
> Open and Co are generally used here.
>
> Is is OK?
> Some points I've forgotten?
>
> Thank you for your response;
> Pat.



I think that's quite OK. Maybe a small point, you can read
from a character device using fread, or fgetc, for instance
you can read from the keyboard...

 
Reply With Quote
 
Patrice Kadionik
Guest
Posts: n/a
 
      02-24-2005
Hi Jacob,
You're right!
You may use fread on a character device (a serial line for example).
Interesting when the byte stream is ASCII character oriented...
Thanks;
Pat.

jacob navia wrote:
> Patrice Kadionik wrote:
>
>> Hi all,
>>
>> I want to make a brief comparison between read() and fread() (under a
>> Linux OS).
>>
>> 1. Family read and Co: open, close, read, write, ioctl...
>> 2. Family fread and Co: fopen, fclose, fread, swrite, fcntl...
>>
>>
>> Family read and Co:
>> - are syscalls.
>> - are not formatted IO : we have a non formatted byte stream.
>> - don't use the Linux buffer cache.
>> - generally used for accessing character devices.
>>
>>
>> Family fread and Co:
>> - are functions of the standard IO libc (glibc).
>> - use an internal buffer (in their coding)
>> - are formatted IO (with the "%.." parameter) for some of them.
>> - use always the Linux buffer cache.
>> - generally used for accessing bloc devices.
>>
>> When I'm opening an ordinary file on a HD (bloc device), I'm always
>> using the buffer cache with open or fopen. In case of fopen, I'm using
>> in addition an internal buffer when I'm doing a fread or fwrite for
>> speeding HD access.
>> When I'm opening an character device, I'm not using the buffer cache.
>> Open and Co are generally used here.
>>
>> Is is OK?
>> Some points I've forgotten?
>>
>> Thank you for your response;
>> Pat.

>
>
>
> I think that's quite OK. Maybe a small point, you can read
> from a character device using fread, or fgetc, for instance
> you can read from the keyboard...
>

 
Reply With Quote
 
Eric Sosman
Guest
Posts: n/a
 
      02-24-2005


Patrice Kadionik wrote:
> Hi all,
>
> I want to make a brief comparison between read() and fread() (under a
> Linux OS).


Only a few of your questions are about the C language,
so I will give very brief answers. For more information,
please try a Linux or Unix newsgroup.

> 1. Family read and Co: open, close, read, write, ioctl...
> 2. Family fread and Co: fopen, fclose, fread, swrite, fcntl...


I think "swrite" should be "fwrite." Also, "fcntl" does
not belong in this list.

> Family read and Co:
> - are syscalls.
> - are not formatted IO : we have a non formatted byte stream.
> - don't use the Linux buffer cache.


They probably *do* use the buffer cache when reading
and writing disk files.

> - generally used for accessing character devices.


No; they can be used with any devices.

> Family fread and Co:
> - are functions of the standard IO libc (glibc).


They are library functions specified by the C language
Standard.

> - use an internal buffer (in their coding)


Usually, but not necessarily.

> - are formatted IO (with the "%.." parameter) for some of them.
> - use always the Linux buffer cache.


The probably do *not* use the buffer cache when reading
and writing things that are not disk files.

> - generally used for accessing bloc devices.


No; they can be used with any devices the implementation
supports.

> When I'm opening an ordinary file on a HD (bloc device), I'm always
> using the buffer cache with open or fopen. In case of fopen, I'm using
> in addition an internal buffer when I'm doing a fread or fwrite for
> speeding HD access.


Usually, but not necessarily.

> When I'm opening an character device, I'm not using the buffer cache.
> Open and Co are generally used here.


You are probably not using the buffer cache, but there
is no problem using fopen() with these devices -- think about
using getchar() to read keyboard input, for example.

> Is is OK?
> Some points I've forgotten?


comp.unix.programmer, or Linux newsgroups.

--
(E-Mail Removed)

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-24-2005
Patrice Kadionik <(E-Mail Removed)> writes:
> I want to make a brief comparison between read() and fread() (under a
> Linux OS).


fread() is defined by the C standard; read() is not. For more
details, try a Linux-specific newsgroup, or perhaps
comp.unix.programmer.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
Patrice Kadionik
Guest
Posts: n/a
 
      02-24-2005
OK,
sorry...
Pat.
Keith Thompson wrote:
> Patrice Kadionik <(E-Mail Removed)> writes:
>
>>I want to make a brief comparison between read() and fread() (under a
>>Linux OS).

>
>
> fread() is defined by the C standard; read() is not. For more
> details, try a Linux-specific newsgroup, or perhaps
> comp.unix.programmer.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
open/fopen read/fread in multithreaded environment. Sheth Raxit C Programming 1 11-23-2007 07:07 AM
Help with FileInputStream and DataInputStream - porting c++ fread function into Java Patrick Java 6 07-13-2004 06:22 PM
fread can not read particular data Meenakshi Matai C Programming 4 06-24-2004 03:40 PM
Equivalent of "fread" C function in Java news.amnet.net.au Java 2 01-15-2004 01:55 PM
fread gives only the first 4 bytes ?? Axel C++ 12 10-27-2003 12:21 PM



Advertisments