is fopen/fseek/fread buffered?

J

John

I have a file open using fopen and am reaing using fread.
Does this mean that the OS (linux) already buffers this
file? What is the buffer size? Can I change it?

Thanks,
--j
 
W

Walter Roberson

I have a file open using fopen and am reaing using fread.
Does this mean that the OS (linux) already buffers this
file?
Yes.

What is the buffer size?

System dependant.
Can I change it?

Please see the setbuf() family of calls.
 
S

SM Ryan

#
# I have a file open using fopen and am reaing using fread.
# Does this mean that the OS (linux) already buffers this
# file? What is the buffer size? Can I change it?

There are two kinds of bufferring going on: your program's stdio
buffers in your program's address space, and the system's buffers
hidden inside the kernel's address space. You can adjust the
stdio buffers with setbuf and setvbuf. You need system dependent
calls to control the kernel's buffers. For example fflush flushes
your program's stdio buffers to the kernel, but the kernel might
not flush its buffers all the way to disk immediately.

I think most stdio implementations discard their buffer contents
after an fseek. On a VM system like linux, the kernel buffers are
page frames managed by the virtual memory page replacement
algorithm.

If you need to do a lot of random jumping around in a file,
you might consider a system dependent memory mapping instead
of stdio.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

fseek 17
fopen 20
Fread problem 52
feof(), fseek(), fread() 20
fopen 17
fread() 6
fseek() 6
problem with fseek 14

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top