public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
* Does a FFI_STRUCT type really need the elements array?
@ 2017-06-22  2:34 Kaz Kylheku
  2017-06-22 12:01 ` Anthony Green
  0 siblings, 1 reply; 3+ messages in thread
From: Kaz Kylheku @ 2017-06-22  2:34 UTC (permalink / raw)
  To: libffi-discuss

Hi libffi users,

Here is the thing. Suppose I have a sophisticated FFI implementation
which uses libffi.  Of course I've done all the struct layout 
calculations
yourself: the offset of every member, taking into account its alignment 
to
generate any padding in between them and at the end. (I need this in 
situations
not involving libffi!)

Yet, I have to mirror this information in the libffi data structure:
a FFI_STRUCT type has to have an elements[] array of types. Presumably
libffi just walks these, redundantly doing the same calculations to get
the offset of every member, total size with padding and alignment.

Can't we dispense with the elements[] array and just punch in the size
and alignment values into the struct type (that are supposed to be left
zero?)

Or is there some compromise: a one-element elements[] array (well two, 
with
null termination), where a single element indicates the size and
alignment somehow.

Or how about a one-element array whose one and only pointer is the
null terminator; with the size and alignment punched in: would that
work?

It's wasteful to allocate, initialize and free these arrays and to have
libffi walking over them.

Any words of wisdom?

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-06-22 17:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-22  2:34 Does a FFI_STRUCT type really need the elements array? Kaz Kylheku
2017-06-22 12:01 ` Anthony Green
2017-06-22 17:12   ` Kaz Kylheku

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).