Hey everyone,

I'm trying to use @cpp ccall() to call myfunc() in a custom shared library 
I wrote in C++, and I noticed there is some overhead if I put the @cpp 
ccall inside a function.

The relevant portion of my Julia code:
# mypath is a constant string type that specifies the path of my custom 
shared library

function usecppfunc!(out,a,b)
    @cpp ccall((:myfunc, mypath), Void, (Ptr{Float64}, Ptr{Float64}, Ptr{
Float64}, Int32), out, a, b, int32(length(a)) );
    return nothing;
end

@time @cpp ccall((:myfunc, mypath), Void, (Ptr{Float64}, Ptr{Float64}, Ptr{
Float64}, Int32), out, a, b, int32(length(a)) );
@time cversion(out2,a,b);

The output:

> elapsed time: 1.0682e-5 seconds (48 bytes allocated)
> elapsed time: 0.002791817 seconds (59664 bytes allocated)
>

The @cpp ccall() wrapped in a function is much slower than the one I called 
from the Julia REPL. I suspect there is some kind of garbage collection 
overhead at the end of the usecppfunc!() call. Your help is greatly 
appreciated!

Reply via email to