caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ctypes - Advice for binding big structs?
@ 2016-02-28  0:12 Malcolm Matalka
  2016-02-28  0:56 ` Jeremy Yallop
  0 siblings, 1 reply; 3+ messages in thread
From: Malcolm Matalka @ 2016-02-28  0:12 UTC (permalink / raw)
  To: caml-list

I have a large/complex struct I am trying to create bindings for
operations on it in Ocaml.  I have an API that tells me how many bytes
the struct is so I can allocate it just fine and pass it around to C
functions I've bound with ctypes.  But some data in it is accessed via
members.  I started implementing a structure in ctypes for it, but it's
getting large and awkward.  Are there any best practices around doing
this?

Some concerns I have:

- It seems fragile - a different version of the library might have
  different members in the struct so keeping my ocaml code in-synch
  seems error prone.

- It's annoying because the struct has a lot of members I don't care
  about in my case.  I only want access to a few members that have
  important details.

- The struct is large with lots of types that I don't necessarily want
  to create so creating the struct becomes somewhat awkward.  If I know
  the size of the types I might be able to pretend it's an array of N
  chars or something instead of trying to implement the type just to
  fill out this struct, but I don't know if that is valid.

- I thought about making C code that implements getters/setters for the
  struct elements I want.  The C code will always be correct, but that
  also feels like a lot of overhead if I'm using this struct in a tight
  loop.  I really just want to access that piece of memory, going in and
  out of a C call just seems like too much work.

Any suggestions?

Thanks,
/Malcolm

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

end of thread, other threads:[~2016-02-28 19:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-28  0:12 [Caml-list] ctypes - Advice for binding big structs? Malcolm Matalka
2016-02-28  0:56 ` Jeremy Yallop
2016-02-28 19:10   ` Malcolm Matalka

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 NNTP newsgroup(s).