Page 1 of 1

File handling.

Posted: Tue Nov 22, 2005 12:27 am
by stonedzealot
Sorry to post them quick and thick, but when one problem is solved, ten other follow. I'm sure we all know how that is.

Basically, I'm wondering how much of a file should remain loaded in memory until it's freed. I mean, you fopen a file and you've got this pointer hanging around and you're fseeking in it, but should the OS keep updating like a 1kb buffer for the file, or does it allocate more as it goes up to a point?

Also, I understand that successive reads to a file can be much simplified on an ext2 or 3 implementation because you can just keep track of a single inode number and then use that to reference the rest of the file. With other file systems like VFAT and etc. still have one little datum that I can store to quickly re-lookup a file? The reason I ask is that I'm thinking of the generic file pointer for a file on any fs, and how I can generalize it.

Re:File handling.

Posted: Tue Nov 22, 2005 1:54 am
by Solar
wangpeng wrote: Basically, I'm wondering how much of a file should remain loaded in memory until it's freed. I mean, you fopen a file and you've got this pointer hanging around and you're fseeking in it, but should the OS keep updating like a 1kb buffer for the file, or does it allocate more as it goes up to a point?
You might want to have a closer look at <stdio.h>, more specifically the setbuf() function and the BUFSIZ macro. In a nutshell, C assumes a fixed-size buffer and allows the user to set the buffer (and its size) explicitly.