Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!husc6!purdue!umd5!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: magic cookies given back by ftell, and used in fseek Message-ID: <11696@mimsy.UUCP> Date: 27 May 88 19:51:03 GMT References: <129@lakart.UUCP> <1024@cresswell.quintus.UUCP> <4253@haddock.ISC.COM> <11695@mimsy.UUCP> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 41 In article <11695@mimsy.UUCP> I proposed making `seek cookies' in the following manner: >Allocate a block (`array') of real information, and return indicies >into this block (a la file descriptors). The block can be expanded as >necessary by using realloc(). I then noted that >The Unix kernel simplifies the task by fixing the number of descriptors >(usually at something like 20 or 64 or 256). I stopped here because the fire alarm was going off in my apartment building. (False alarm, fortunately.) There is a more serious problem with this scheme, and that is that there is no decent way to tell when an ftell cookie is dead and can be freed. A small, limited number of cookies is insufficient. Of course, one can flush all the cookies for a file when that file is closed, but it is easy to imagine a file that stays open for weeks at a time, seeking all the while. Various solutions exist, none particularly clean. The most obvious are to add a function for disposing of seek cookies (`fkillseek()'?), and to deem that a cookie dies when it is used: long save_pos; save_pos = ftell(f); // work on f (void) fseek(f, save_pos, 0); /* if we need it again, we must reactivate it: */ save_pos = ftell(f); The former requires an incompatible addition to stdio, while the latter requires an incompatible change to those things that use stdio. Which would be easier remains uncertain, although at least the latter rule has the virtue of simplicity. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris