From mboxrd@z Thu Jan 1 00:00:00 1970 From: cowan@mercury.ccil.org (John Cowan) Date: Tue, 22 Mar 2016 00:00:04 -0400 Subject: [TUHS] Etymology of the open file table? In-Reply-To: References: Message-ID: <20160322040004.GB25603@mercury.ccil.org> 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 at 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