Can anyone give a demo to me with the “dl” function.I’m not quite sure how to use this function.
dl
dynamic link
Signature: K dl(V* f, I n)
Function takes a C function that would take n K objects as arguments and returns a K object. Shared library only.
Returns a q function.
on osx, putting resulting a.so in $QHOME/m64
$ more Makefile
m64:
gcc -bundle -undefined dynamic_lookup a.c -o a.so
$ more a.c
#define KXVER 3
#include"k.h"
static K myadd(K x,K y){
if(xt!=-KJ||y->t!=xt)
return krr(“type”);
return kj(xj+y->j);
}
K f(K x){
return dl(myadd,2);
}
$ more a.q
f:a 2:(
f;1)
f[3;4]
$ q a.q
KDB+ 3.7t 2019.11.15…
7
q)\
Why not just export myadd directly and call it in kdb? Why do you have to use “dl” function in the example?
? 2019?11?16??? UTC+8??11:13:29?Charles Skelton???
on osx, putting resulting a.so in $QHOME/m64
$ more Makefile
m64:
gcc -bundle -undefined dynamic_lookup a.c -o a.so
$ more a.c
#define KXVER 3
#include"k.h"
static K myadd(K x,K y){
if(xt!=-KJ||y->t!=xt)
return krr(“type”);
return kj(xj+y->j);
}
K f(K x){
return dl(myadd,2);
}
$ more a.q
f:a 2:(
f;1)
f[3;4]
$ q a.q
KDB+ 3.7t 2019.11.15…
7
q)\
yes, the most usual case is exactly as you say, to setup the mapping using 2: for each function.
Another example
https://github.com/KxSystems/embedPy/blob/master/py.c#L51
Using dl enables you to reduce symbol scope in the shared lib.
I’m so sorry I still can’t find the difference between
#define F(f,i) js(&n,ss(#f));jk(&v,dl(f,i));
F(eval,1)
and
#define F(f) js(&n,ss(#f));jk(&v,f);
F(eval)
? 2019?11?17??? UTC+8??6:37:46?Charles Skelton???
yes, the most usual case is exactly as you say, to setup the mapping using 2: for each function.
Another example
https://github.com/KxSystems/embedPy/blob/master/py.c#L51
Using dl enables you to reduce symbol scope in the shared lib.
in the first, the actual code from embedpy, it is storing the k object returned from dl(). That k object contains the function pointer and the function rank, and has type 112. This can be passed around, reference counted, used for function invocation, and freed when no longer used.
in the second you are storing just the function pointer, no function rank, and is invalid anyway as type 0 lists must contain pointers to k objects.
OK, I see, thank you so much.
? 2019?11?19??? UTC+8??6:33:56?Charles Skelton???
in the first, the actual code from embedpy, it is storing the k object returned from dl(). That k object contains the function pointer and the function rank, and has type 112. This can be passed around, reference counted, used for function invocation, and freed when no longer used.
in the second you are storing just the function pointer, no function rank, and is invalid anyway as type 0 lists must contain pointers to k objects.