by zten · 2y ago · 0 comments
Decompiled class file:
try {
var4 = File.createTempFile("libzstd-jni-1.5.0-4", "." + libExtension(), var0);
var4.deleteOnExit();Though in the example given, I do see your point now. You'd have to make sure the DLL was unloaded before the delete-on-exit happened.
You can just load as a resource. We do this internally since much of network stack is C. But we use JNI because code is older than Java 22.
Stackoverflow is full of "copy it into a temp file" solutions. ChatGPT keeps saying "sorry" but still insists on copying it into a temp file :)
[0] - https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi...
new FileOutputStream(tmpFile)
Apologies.I have some extremely unwieldy off-heap operations currently implemented in Java (like quicksort for 128 bit records) that would be very nice to offload as FFI calls to the corresponding a single-line C++ function.
Except if we're talking about some college student or hobbyist picking their first language and exploring the language space...
But even if it was needed, such records can be commonly represented by the same structs both at C#'s and C++'s sides without overhead.
An array of such could be passed as is as a pointer, or vice versa - a buffer of struts allocated in C/C++ can be wrapped in a Span<Record128> and transparently interact with the rest of standard library without having to touch unsafe (aside from eventually freeing it, should that be necessary).
Stay in the swamp :)