home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ontek!mikey
- From: mikey@ontek.com (euphausia superba)
- Newsgroups: comp.lang.c
- Subject: Re: Locating A Record Within A File
- Message-ID: <2197@ontek.com>
- Date: 11 Dec 92 19:42:33 GMT
- References: <1992Nov24.174656.25265@nosc.mil> <1992Dec03.100851.5809@cadlab.sublink.org>
- Organization: Ontek Corporation -- Laguna Hills, California
- Lines: 30
-
- In comp.lang.c, martelli@cadlab.sublink.org (Alex Martelli) writes:
- | mitch@nosc.mil (Ray Mitchell) writes:
- |
- | :Assume that a file consists of a series of records and it is desired to
- | :locate a specific record. My assumption is that in the general case it
- | :is not portable to simply fseek or fsetpos to (sizeof(record) * recordnumber)
- | :since a file can contain more than just the individual bytes forming each
- | :record. Instead, the file should start with a table of offsets, initially
- | :determined by ftell or fgetpos, which may be later given back to fseek or
- | :fsetpos to locate the desired record.
- |
- | [discussion of solutions to problem of growing the size of the
- | lookup table]
-
- I sense a fallacy here. Since the lookup table itself is part
- of the file, you can't index into it any more portably than you
- could have indexed into the records themselves. The overhead of
- reading is that of sequentially reading the table of record
- offsets until finding the offset for the record you're interested
- in. This will be faster if the size of the entries in the index
- is significantly smaller than the size of the records, but it will
- be a far cry from fseek.
-
- Possible ways of achieving the random-access behavior you describe
- are (a) carrying around an fpos_t wherever you would have previously
- wanted to have "record number" or (b) constructing a lookup table
- in memory ahead of time.
-
- the krill, i guess off_t is out of the question
-
-