Jump to content
Excelsior Forums

mpedzisai

Members
  • Content count

    0
  • Joined

  • Last visited

    Never

Community Reputation

0 Neutral

About mpedzisai

  • Rank
    Newbie
  • Birthday 01/01/01
  1. How to free memory allocated in external function

    >>> As to your question, I have a question for you before answering: If it were C not Java code, how would you free the memory? <<< To answer your question, I would probably free the memory in the calling functionm after I have used JNAction. Example void callingFunc() { JNIAction a= DLLGetDefaultAction"1"); int id = a.id; //etc ///NOw I am done with JNIAction I am ready to free the memory allocated to JNIACtion.name (a char *) free(a.name); } In the same breath, my expectation was that xFunction would recognize the fact that after returning an object that was allocated in C as shown in my example, I would have no access to it anymore, unless I decided to store it some place in the DLL, only to come back and release memory after I have finished copying the data in Java. If I have to that for every obect that I allocate using malloc then xFunction totally useless! If I knew that before I bought it I would definitely have not bought it but than the documentation is murky and somehow leaves the impression that any pointers that you do not free using xFunction's free() method are indeed cleaned up for you by the library. Thanks, Melody
  2. It looks like this forum is moderated by a fellow called Snowman but I have noticed that he or anyone from the xFunction team rarely if ever responds to questions. Is that because that is Excelsior policy to ignore questions or are people asking dump questions. I like what I have seen of xFunction but the lack of response to any questions whatsoever is very worrisome. I have requested a phone call from Excelsior, called the Russian offices and posted questions here. None of these avenues have yielded a response. Is that how things work? I bought this product and if the owner of the software cannot help me with a few basic questions then there is a problem. After buying!
  3. How to free memory allocated in external function

    Thanks for the response. Can you give me an example of how you would do that. If you notice in the example code, the whole structure (JNIAction) is initialized and returned from within a function. In other words it is not stored anywhwre after it has been returned to xFunction. How then would I have access to it so I can free memory. In any event, are you saying that there is no way to free memory, either explicitly or automatically, from xFunction. If that is the case it seems to me that that would be dumb and xFunction would be no convenience at all because then it would leave the programmer with the most classic of problems when crossing the Java/C++ bridge. Thanks, Melody
  4. I am a recent adoptee of xFunction. I use it in a servlet that calls a WIndow DLL and return all kinds of data including structures. Haveling looked through the docs, I have not been able to find definitive information about how to free memory that has been allocated in an external dll/function using malloc or new. Does xFunction automatically free pointers returned to it? Does the responsibility for freeing malloc'ed memory rest with the DLL or xFunction? Its a bit unclear. Example below. External function typedef struct JNIAction_s { int id; char *name; } JNIAction; extern "C" DllExport JNIAction _stdcall DLLGetDefaultAction(LPTSTR as_sessionid) //assumes that session established already { AFX_MANAGE_STATE(AfxGetStaticModuleState()); JNIAction a; a.id = 1; a.name = strdup("Action Name");//allocated on heap -- how do I free this when JNIAction is sent back to xFunction return a; } Java Side a) Structure public class JNIAction extends Structure { /** Creates a new instance of JNIAction */ public JNIAction() { } public int id; public String name; public String defineLayout() { return "int id, CSTRING name "; } } Calling the external function xFunction l_func = new xFunction("SOMEDLL", "JNIAction DLLGetDefaultAction(CSTRING)"); JNIAction jniaction = (JNIAction)l_func.invoke("1", Argument.CSTRING)); The question is how the name member of JNIAction will be freed. Does that happen automatically in xFunction If not what can I call in xFunction to ensure that pointer related member variables like JNIAction.name are freed? If xFunction does not automatically free the memory and does not have a facility for freeing memory explicitly, does anybody know of a good way to free memory allocated on the heap in an external function. Thanks, Melody
  5. Unloading the JVM and xFunction DLL

    Hello I am using xFunction in my web application which runs inside Tomcat server. When create the xFunction methods, the xFunction library automatically loads the xFunction DLL and creates two JVMs, one with approximately 10Mbytes ram and another with a little more memory. What are these two JVMs for? How do I unload them when my main JVM is killed or terminated? How do I terminate or unload the xFunction.dll? Is there a function in the xFunction library for unloading the DLL and the acompanying JVMs. The problem is that if I leave these JVMs and the DLL loaded, the next time my up starts it fails to reload xFunction. Is there any way to reuse an xFunction DLL that is already loaded into memory instead of failing with UnsatisfiedLinkError. Thanks, Melody
×