[erlang-questions] Calling C code

Vlad Dumitrescu vladdu55@REDACTED
Tue Jan 23 09:16:40 CET 2007


On 1/23/07, Per Hedeland <per@REDACTED> wrote:
> "Vlad Dumitrescu" <vladdu55@REDACTED> wrote:
> >Question 1: by using a linked-in driver, are the calls direct, or do
> >they go through the same layers as to a port?
> It seems this question wasn't actually answered - and the answer is
> perhaps not obvious since the question is a bit weird.:-) The only way
> to interact with a linked-in driver is through a port, so of course it's
> not just "as" but actually "to a port"... However I suspect that maybe
> by "a port" you mean "an external port program", and in that case there
> is of course a potentially huge difference in communication overhead
> compared to a linked-in driver, as the external program runs in a
> separate OS process (i.e. there will be context switches) and all
> communication is via pipes.
> Whether that means that "the calls are direct" depends on what calls
> you're thinking of:-) - as the interaction is through a port, there's no
> way to "directly" "call" arbitrary functions in the driver, and
> depending on what data you want to exchange with the driver, it may need
> some processing by your Erlang code and/or the runtime system, but it's
> all "just" function calls within the same process. Undoubtedly BIFs are
> more "direct", but it may not motivate going down that path...

You are right, of course... It is a mix of mixing things up a little
(external port vs linked in driver) and of badly formulating the
question... and a bit of not rtfm, actually :-)

The layers I referred to were actually the serialization layer used in
communicating with a port. What I would really like to be able to do
is to be able to access Erlang data directly, i.e. have a pointer to
the data, not a serialized form or a copy of it -- which is safe if it
is read-only, as in my case, but not in the general case. But for that
a BIF may be needed...

I am investigating alternative solutions, I was just hoping there was
a relatively quick way to test how this could work or I have to take a
completely different approach.

best regards,

More information about the erlang-questions mailing list