Re: fopen and memory usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 26Sep2007 13:58, aragonx@xxxxxxxxxx <aragonx@xxxxxxxxxx> wrote:
| Okay, so I use fopen and it gives me a stream.  Now when I call fread (say
| for 100K) on my large file (2G) it will try to read the first 64K
| regardless of size and populate *ptr.

Yes. It will read a chunk of the data into the buffer. For a regular
file it will usually be the whole 64kb. For some other things it may be
less (eg a terminal).

| If size is larger than 64K (100K
| here) it will then read another 64K?

After you, the programmer, have consumed the data currently in the
buffer, yes. If you call fread (or scanf etc) with data in the buffer,
that data will be used to satisfy your reuqest. If more is needed, more
is read from the file into the (now empty) buffer).

| Does it use the same buffer space
| (effectively only using 64K)

Yes.

| and is that buffer space outside the memory
| footprint of my application?

No. fopen uses stdin, and that is a library inside your app.
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

Early to bed and early to rise makes a man healthy and wealthy with bags
under his eyes. - Dave Cochran, <cochran@xxxxxxxxxxxxx>


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux