Dan Cross scripsit:
Those file structures are collected into a single,
global table. The
question is why this latter table? One could rather imagine an
implementation where open() allocates (e.g., via malloc()) a new 'struct
file' that contains as a structure field an 'int refcnt' that is
incremented when a descriptor is dup()'d or as a side-effect of a fork(),
and is decremented as a result of a close(); when 'refcnt' drops to zero,
the structure could be freed with e.g. 'mfree'. What is the benefit of
'struct file file[];'?
Sure you could, but it would be more complex, slower, and less robust.
"When in doubt, use brute force." --ken
--
John Cowan
http://www.ccil.org/~cowan cowan(a)ccil.org
He made the Legislature meet at one-horse tank-towns out in the alfalfa
belt, so that hardly nobody could get there and most of the leaders
would stay home and let him go to work and do things as he pleased.
--H.L. Mencken's translation of the Declaration of Independence