[erlang-questions] Calling C code

Per Hedeland <>
Tue Jan 23 01:41:06 CET 2007

"Vlad Dumitrescu" <> wrote:
>I have a tricky question. I have a distributed application that needs
>to do some simulations. Not very extensive, but a lot of them. Doing
>it in Erlang is way too slow and talking through a port is also too
>slow, but I really need the distribution and the higher level stuff
>that Erlang provides.
>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...

--Per Hedeland

More information about the erlang-questions mailing list