Question. Shouldn't ffi be calculating the offsets automagically for us, since all that is distributed is ruby code, and "automatic struct layout" thence not be necessary? I would have expected that... Thanks. -r
> Question. > Shouldn't ffi be calculating the offsets automagically for us, since > all that is distributed is ruby code, and "automatic struct layout" > thence not be necessary? I would have expected that...
It does, the wiki just hasn't been updated ... in about a year - so feel free to fix it up.
Basically, to have FFI calculate offsets for you, you drop off the offset out of the triplet.
i.e. instead of class Foo < FFI::Struct layout :a, :long, 0, :b, :int, 4 end
You would use: class Foo < FFI::Struct layout :a, :long, :b, :int end
That will calculate the offset of :b automatically for you, and take into account 32bit vs 64bit, minimum alignments, tail padding, etc.
Wayne Meissner <wmeiss...@gmail.com> wrote: > 2009/12/18 rogerdpack <rogerpack2...@gmail.com>: > > Question. > > Shouldn't ffi be calculating the offsets automagically for us, since > > all that is distributed is ruby code, and "automatic struct layout" > > thence not be necessary? I would have expected that...
> It does, the wiki just hasn't been updated ... in about a year - so > feel free to fix it up.
> Basically, to have FFI calculate offsets for you, you drop off the > offset out of the triplet.
> i.e. instead of > class Foo < FFI::Struct > layout :a, :long, 0, :b, :int, 4 > end
> You would use: > class Foo < FFI::Struct > layout :a, :long, :b, :int > end
> That will calculate the offset of :b automatically for you, and take > into account 32bit vs 64bit, minimum alignments, tail padding, etc.
We need a Struct wiki page similar to what jacius did for Enums anyway.
Is there any reason why Wayne shouldn't just delete the automatic struct layout page once the struct page exists?