Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!rutgers!texbell!sugar!peter From: peter@sugar.hackercorp.com (Peter da Silva) Newsgroups: comp.sys.amiga.tech Subject: Re: Static limits (Re: AmigaDos directory knowledge + (new) BENCHMARK I DID) Message-ID: <4669@sugar.hackercorp.com> Date: 4 Dec 89 13:11:36 GMT References: <24370@swrinde.nde.swri.edu> <8787@cbmvax.UUCP> <4659@sugar.hackercorp.com> <5649@cps3xx.UUCP> Reply-To: peter@sugar.hackercorp.com (Peter da Silva) Organization: Sugar Land Unix - Houston Lines: 92 In article <5649@cps3xx.UUCP> porkka@frith.UUCP (Joe Porkka) writes: > In article <4659@sugar.hackercorp.com> peter@sugar.hackercorp.com (Peter da Silva) writes: > >In article <8787@cbmvax.UUCP> daveh@cbmvax.UUCP (Dave Haynie) writes: > >> Static limits are a bad thing, period. MS-DOS even makes you tell it how > >> many files you'll allow to be open at once. Apparently OS/2 suffers from > >> the same faulty thinking... > >Like the limit of 32 SigBits for an AmigaOS task? The Amiga isn't immune to > >the static limit problem. > Yes but sigbits can be shared between multiple event generators. > It is somewhat harder to share file handles between multiple files :-) struct FileHandle { struct FileHandle *next; struct FileHandle *prev; FILE *fp; char *name; char *mode; off_t offset; int valid; long used; }; struct FileHandle *fhroot; /* circular doubly-linked list */ long seq = 0; struct FileHandle *fhopen(file, mode) char *file, *mode; { struct FileHandle *fh; fh = new(FileHandle); if(!(fh->fp = fopen(name, mode))) { recover_fp(); if(!(fh->fp = fopen(name, mode))) { dispose(FileHandle); return 0; } } fh->name = clone(name); fh->mode = clone(mode); fh->used = seq++; insert(fh, fhroot); return fh; } fhclose(fh) struct FileHandle *fh; { FILE *fp; remove(fh); fp = fh->fp; dispose(fh->name); dispose(fh->mode); dispose(fh); return fp?fclose(fp):SUCCESS; } fhread(fh, bytes, count) { if(!fh->valid) return 0; if(!fh->fp) { recover_fp(); if(!(fh->fp = fopen(fh->name, fh->mode))) { fh->valid = 0; return 0; } fseek(fh->fp, fh->seek, 0); } fh->used = seq++; return fread(bytes, count, 1, fh->fp); } recover_fp() { Find fh with lowest fh_seq; fh->offset = ftell(fh->fp); fclose(fh->fp); fh->fp = 0; } ... and so on. -- Peter "Have you hugged your wolf today" da Silva `-_-' 'U` "Really, a video game is nothing more than a Skinner box." -- Peter Merel