Traduisez - Übersetzen - Traduzca - Traduza - Tradurre - Translate

VanLUG Email Archive

VanLUG Mailing List
Linux Programming Question

New Message Reply About this list Date view Thread view Subject view Author view

16-bit aligned (michaelw@unixg.ubc.ca)
Mon, 22 Mar 1999 13:59:38 -0800


Ok, so I'm writing an API to access records of a database (it's the JAM
message base format from the old Fidonet days, but that's not
important).. The problem boils down to this:

I have a bunch of variable length records that look like this:

Rec 1:
        int rectype
        int unused
        int datasize
        char[datasize] //so this is a datafield of size datasize
Rec 2:
        int rectype..
        etc..

 .
 .
 .

Rec n:
        etc..

        
These are actually subrecords of a record, and many records are in the
index file that i am parsing. The problem is that datasize will not be
32-bit aligned (it might not even be 16-bit aligned), so that if i read
all the subrecords into a buffer and access, say, record two by doing
this:

(my_struct*)TheRecords[sizeof(record 1)]

..won't I get a byte-alignment error if this is not an nicely aligned
address? I might need to port this to SunOS later. What about that?

The easy way, of course, is to lseek to the beginning of the second
record and read that into a nicely aligned struct, but i want to
minimize disk reads. Or am i being too anal about speed? (like, it'll
all be cached anyway, right?)

What do you think? Any C database people here?

thanks,
myk

PS: Probably not too many people here care about this, so why don't you
respond in private to me. And if you're interested in this, send me a
private email and I will bounce my replies back to you.

-- 
/*
 * mike white  mailto:michaelw@unixg.ubc.ca
 * v: 604.221.2438
 * http://www.ugrad.cs.ubc.ca/spider/o3n1/
 */


New Message Reply About this list Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b3 on Mon 22 Mar 1999 - 13:59:05 PST