I haven't called a custom DLL in some time now; since I have more spare
time, I was noodling around with old code.

Took me a while to notice what was going on; "pass by reference" where you
send a J array to a DLL to be written to wasn't working the way it had in
the past. It actually is documented, but I had to read about it in the
forum (this was
<http://jsoftware.2058.n7.nabble.com/j807-cd-pass-array-arguments-td80898.html#a80909>
helpful) to understand what it meant.

I propose that memu be documented here as well as on the "calling DLLs" page

https://code.jsoftware.com/wiki/Guides/DLLs/Memory_Management

Also the use of & vs * in the signature is far from clear to me in the calling
DLL <https://code.jsoftware.com/wiki/Guides/DLLs/Calling_DLLs>s page.
In the past, if I had a function signature like this, and want variable XX
to be populated in the dll (and returned to J), everything would be fine:
(for a C function int MyIntMod (int len, int vec[]) which modifies the
vector of length len )

cmd=. LIBNAME,' MyIntMod i i *i'
XX =. nr $ 1-1
cd cmd;nr;XX
(etc etc)

Now, it only works if I do the following

cmd=. LIBNAME,' MyIntMod i i &i'
XX =. memu nr $ 1-1
cd cmd;nr;XX


Is this the correct way for modify a vector passed by reference in a DLL?
If so, when I read the documentation, it looks like it should work with *i
as well.

"The * type is a pointer to values. A * can be followed by c w u s i l x f d
 or j to indicate the type of values. The DLL can read or write this
memory. The memory is unaliased.

The & type is same as * except the memory is not unaliased as it is assumed
to be constant."
Can someone add a sentence for my (presumably common) dll use case? I was
able to figure it out, but it took me a bit.

-SL
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to