none
Unmanaged Exports DLL RRS feed

  • Question

  • Hello ,

    I'm trying to implement C# application that returns arrays of object to java through JNA. I'm adding this line [RGiesecke.DllExport.DllExport] to make that part of program unmanaged from managed code.

     [RGiesecke.DllExport.DllExport]
            static public void GetProcessInfo(out IntPtr[] pp,out int pCount)

    and assigning chunk of memory size of object so that i can read pointer from java and can read those memory.

    And I can free memory whenever I want by cleaning the chunk of memory I've assigned from C#. But seems like I'm able to read objects from java but when I tracking memory It's increasing every time java makes native calls to C#. So can anybody tell me how can I resolve this problem or can anybody drive me to solution where I can make my C# application unmnaged, I can assign memory block and can clear it so I don't face memory leak issue.

    Thanks,

    Rajat Kinkhabwala 

    Monday, March 19, 2018 2:53 PM

Answers

  • Hi Rajat Kinkhabwala,

    For your question, I do not know java well. But after discussion with the supporter of Java, when you invoke the C# method in java, we are not sure what part causes the memory leak issue.

    Please try to use a return value instead of out parameter. And I am confused about C# code. Why you used struct[] as your return value type? Does the code work well only in your C# code? Does the C# code get the memory leak issue?

    In your java code, where you get the memory leak issue?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, April 2, 2018 6:18 AM
    Moderator

All replies

  • You seem to be describing a solution for some requirements you are trying to satisfy but you need help with the solution because the solution does not work. So you are asking for a different solution but you don't describe the requirements. So calm down and describe what you need to do without describing how to do it.

    You have a C# program and you need the output to go to a Java program. What is the current output of the C# program, or what was it before you tried to solve this problem? What is the format of the input to the Java program? It would be better to start from there, then attempt to determine a good way for the C# program to provide the data to the Java program. I don't know enough about Java to help you with that but someone can help you if you provide the information they need.



    Sam Hobbs
    SimpleSamples.Info

    Tuesday, March 20, 2018 2:08 AM
  • Hi Sam,

    I've wrote an application basically send an array of struct to java program using jna from c#. The library I'm using in c# is  RGiesecke.DllExport.DllExport to export the method. I tried like this in c#,

    [RGiesecke.DllExport.DllExport]

    static public void method1 ( out struct[] a)

    {

    // method

    }

    and in java,

    public interface CLibrary extends Library {

    public void method1 (PointerByReference valsRef)

    }

    public static void main(String[] args) throws InterruptedException {

    PointerByReference valsRefPtr = new PointerByReference();

    CLibrary.INSTANCE.method1 (valsRefPtr);

    valsRef.read();

    }

    With this code I'm able to get the data I want from C#, but when I run the program for a while, I get a huge memory leak.

    Thanks,

    Rajat 




    Tuesday, March 20, 2018 12:58 PM
  • Hi Rajat Kinkhabwala,

    For your question, I do not know java well. But after discussion with the supporter of Java, when you invoke the C# method in java, we are not sure what part causes the memory leak issue.

    Please try to use a return value instead of out parameter. And I am confused about C# code. Why you used struct[] as your return value type? Does the code work well only in your C# code? Does the C# code get the memory leak issue?

    In your java code, where you get the memory leak issue?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, April 2, 2018 6:18 AM
    Moderator