lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Peter Cawley wrote:
[...]
> Though you then need to get slightly more creative about encoding the
> type. A double has 52 bits of mantissa; with 48 taken for a
> pointer-sized value, and 1 taken to ensure a quiet NaN, you only have
> 3 bits left to encode the type. If you borrow the sign bit as well,
> then you have 4 bits. For reference, the current implementation in 5.2
> beta uses 6 bits for encoding type.

If the thing you're pointing at is 4-aligned, then you get two free bits
at the bottom of the pointer. If the thing you're pointing at has been
allocated with malloc(), then you get more --- the result of malloc() is
guaranteed to be correctly aligned for any kind of variable, which in
practice usually gives you four bits.

-- 
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "I have always wished for my computer to be as easy to use as my
│ telephone; my wish has come true because I can no longer figure out
│ how to use my telephone." --- Bjarne Stroustrup

Attachment: signature.asc
Description: OpenPGP digital signature