Having my own Java code I'm using C# to call some unmanaged code that call (via JNI) the java code. I'm using JNI since I need to ensure:
- the ability that the Java code will run over real JVM and not over some .NET VM
- the ability to attach to the VM for debugging (IKVM does'nt support it)
- I need free solution
- The current free solutions are not applicable (e.g. IKVM)
Anyway, my question is how can I manage strings passed between these layers in the best manner without leaks. I'm doing something like:
[DllImport(@"MyDll.dll")]
public extern static void receive_message(string receDest, StringBuilder response);
This means I'm allocating the memory for the response in the managed code. I want to avoid that since I don't know in advance the response length. How can I write a JNI appropriate method that will allocate the right buffer for the managed code without leaks. The JNI code should be thread safe.
Any suggestions?
Thanks,
Guy