c - Memory and file pointers -


i'm confused how os "opens" file in c when fopen in code. elaborate, suppose had 100 binary files (say of size 1 mb) open in c

file **fptr;  fptr = calloc(100, sizeof(file *));  (ii = 0; ii < 100; ii++)     fptr[ii] = fopen(filename[ii], "rb+"); 

assume filename , ii defined appropriately.

will os load 100 mb memory, or above code tell program keep these files ready access?

the latter, no data read file until needed, i.e. when call fread() or other i/o function.

of course underlying operating system might decide speculatively read data when file opened, save time later, that's outside control in effect doesn't matter. mean doesn't matter because memory used such speculative buffering need made available applications on demand.

that said, it's not if practical system let fopen() spend time needed read 100 mb though, bad engineering.

also note there might limits on how many files single process can open in parallel. 100 should fine modern systems, though.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -