From: Malcolm Matalka <mmatalka@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] ctypes - Advice for binding big structs?
Date: Sun, 28 Feb 2016 00:12:41 +0000 [thread overview]
Message-ID: <86ziulheva.fsf@gmail.com> (raw)
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
next reply other threads:[~2016-02-28 0:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-28 0:12 Malcolm Matalka [this message]
2016-02-28 0:56 ` Jeremy Yallop
2016-02-28 19:10 ` Malcolm Matalka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86ziulheva.fsf@gmail.com \
--to=mmatalka@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).