Calling C vs Embedding Julia (C code)

Calling C vs Embedding Julia in C code

Hello World,

I am new to Julia, and at the moment I am doing some research about the possibilities of combining an existing C code with new Julia functions.

At the moment I have made two small examples of how to do this. The first example is by passing Julia callback functions to C using ccall and cfunction. And the second example is with embedding Julia into the C code.

I am having a hard time to find advantages and disadvantages of both options (like speed, performance, memory use, easy implementation, etc.). Also, if there is any other option that I am missing of how to do this would be great to know it.

Thanks!

The primary question is where you want the entry-point of your resulting program to live.

If your program is supposed to be a script / command-line utility, then it is probably preferable to call into C from julia; both because C is terrible for this kind of job, and because C really excels in creating shared libraries (C-ABI with dynamic linking is the lingua franca of software; and unsurprisingly C is pretty good at working with it).

If you already have a complex UI fully implemented in C (either graphical or command-line or daemon), then it is probably less work to keep it and embed julia.

If your resulting artifact must be a dynamic library, to be used by programs who are not aware that julia exists, then you must go the embed-julia-in-C route.

Not really different but at least a slight variation that could be of interest if you haven’t already seen it: [ANN] DynamicallyLoadedEmbedding

Thank you for your help!
The main goal is to have to have the benefits of julia like parallelisation, easier to understand scripts, etc.

The julia interface is going to be called millions of times, that is why performance has a huge importance and one millisecond of difference between the two options will have a tremendous impact. And how does the speed is compare to C?

Thanks, I will take a look at it.