lua-users home
lua-l archive

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


On Wed, Jul 6, 2011 at 5:38 PM, David Given <dg@cowlark.com> wrote:
> 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.

Light userdata need not be aligned, light C functions need not be
aligned, and memory for garbage collectable objects can come from a
custom allocator, which might give unaligned addresses.