[erlang-questions] Calling C code
Mon Jan 22 11:37:26 CET 2007
On 1/22/07, Mikael Pettersson <mikpe@REDACTED> wrote:
> On Mon, 22 Jan 2007 10:34:43 +0100, Vlad Dumitrescu wrote:
> > If the answer above is "as to a port", then I had this idea: since
> > hipe is compiling to native code, it might be possible to convince it
> > to create a stub that will just call a statically linked C routine.
> > Question 2 (going mainly to the hipe team), is whether this is feasible at all.
> I think you would be much better off just adding a few BIFs that
> contain your C code, or calls into your C code.
Ok, I see. I was hoping that there was an easier way than writing BIFs.
> When native code calls C code there some important glue in between.
> That glue is implemented by a per-C-function stub statically compiled
> into the runtime system. But you can't just call random C stuff from
> these stubs, they're very much only intended for calling BIFs and
> a small set of helper procedures for the HiPE compiler.
The C code isn't really random, it just does some computations and is
almost completely self-contained (only uses functions in "math.h") and
the algorithm is time-bounded. A perfect candidate for a BIF :-)
I will look at how lists:reverse/1 is implemented, maybe it's not that
difficult as I thought.
> Alternatively you can try to rework your application to batch requests
> so that the calling mechanism isn't performance-critical any more.
Yes, this is an alternative. Trouble is that I need to supervise the
simulations, and I feel that it might be easier to go the "native
call" way than the other.
More information about the erlang-questions