"Heikki Linnakangas" <[EMAIL PROTECTED]> writes:
>> Actually I think neither htonl nor bitshifting the entire 4-byte word is
>> to really work here. Both will require 4-byte alignment. Instead I think we
>> have to access the length byte by byte as a (char*) and do arithmetic. Since
>> it's the pointer being passed to VARSIZE that isn't too hard, but it might
>> perform poorly.
> We would still require all datums with a 4-byte header to be 4-byte aligned,
> right? When reading, you would first check if it's a compressed or
> header. If compressed, read the 1 byte header, if uncompressed, read the
> header and do htonl or bitshifting. No need to do htonl or bitshifting on
> unaligned datums.
It's not easy to require datums with 4-byte headers to be 4-byte aligned. How
do you know where to look for the bits to show it's an uncompressed header if
you don't know where it's aligned yet?
It could be done if you rule that if you're on an unaligned byte and see a \0
then scan forward until the aligned byte. But that seems just as cpu expensive
as just doing the arithmetic. And wastes space to boot.
I'm thinking VARSIZE would look something like:
#define VARSIZE((datum)) \
((((uint8*)(datum)) & 0x80) ?
(((uint8*)(datum)) & 0x7F) : \
(((uint8*)(datum))<< 24 | ((uint8*)(datum))<<16 |
((uint8*)(datum))<<8 | ((uint8*)(datum))))
Which is effectively the same as doing ntohl except that it only works for
left hand sides -- luckily VARSIZE always has a lhs. It also works for
unaligned accesses. It's going to be fairly slow but no slower than doing an
unaligned access looking at nul padding bytes.
---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?