Record locking vs. buffered I/O
Don Eastman
deastman at pilot.njin.net
Mon Nov 13 12:18:57 AEST 1989
Jules d'Entremont writes (which I edited liberally):
> I posted the following to comp.unix.questions but got no responses, so I'll
> try again here.
>
> I have the task of implementing a set of simple database routines.
> Should I even be using buffered I/O at all?
[ Perhaps the mail I sent last week will arrive by Christmas? ]
I believe you should be using read and write system calls rather than
stdio for your data base access routines.
Flushing after each fwrite will eliminate the performance benefit
that usually accrues from using stdio. This is because fflush
will call write which one could have called directly. Also,
the added level of buffering will make the code run more slowly.
On the fread side, the concerns inherent in your questions are well
founded. The buffering done by stdio cannot be used; subsequent queries
must retrieve data from the file, not what was cached in the process,
because the file data may have changed between calls.
You might also reconsider your locking implementation. Are you attempting
to provide serializable transactions?
Don Eastman deastman at pilot.njin.net
More information about the Comp.unix.wizards
mailing list