File handling.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
stonedzealot

File handling.

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:File handling.

Post 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.
Every good solution is obvious once you've found it.
Post Reply