Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2010
    Posts
    6
    Rep Power
    0

    Default JNI Memory Allocation

    Hi,

    I have a problem with a self written c++ dll.
    The dll needs a bit of memory, about 500MB to 1GB but crashes during dynamic allocation.

    The memory allocation is not influenced by any parameter passed from the original java program via the JNI. If it is solely executed as a simple cpp.exe it works absolutely fine, it only crashes as a by JAVA called dll.

    Due to plenty of couts I am definitely sure that it crashes executing the following line of code:

    data = new float[TABLE_SIZE];

    whereas data is a float pointer and TABLESIZE is about 37 million entries. Hence it needs 150 MB space.

    But instead of allocating, it crashes with the error message:

    ---------------------------
    Microsoft Visual C++ Runtime Library
    ---------------------------
    Runtime Error!

    Program: C:\Program Files (x86)\Java\jre6\bin\javaw.exe



    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information.


    ---------------------------
    OK
    ---------------------------


    This happen although I still have 1.8 GB free RAM.

    Does anybody know how JAVA can provide more memory to the dll?

    Thanks a lot!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    Try using a -Xxxx option (get the value of xxx from the javac doc) on the java command to give the JVM more memory.
    Here's an example: -Xmx512M

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Norm View Post
    Try using a -Xxxx option (get the value of xxx from the javac doc) on the java command to give the JVM more memory.
    Here's an example: -Xmx512M
    That doesn't work; the Java heap and the C or C++ heap are two different things (running in the same process space). If you increase Java's heap the less memory is available to your C or C++ JNI code. Here's a nice link that explains memory management for the both.

    kind regards,

    Jos

  4. #4
    Join Date
    Sep 2010
    Posts
    6
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    That doesn't work; the Java heap and the C or C++ heap are two different things (running in the same process space). If you increase Java's heap the less memory is available to your C or C++ JNI code. Here's a nice link that explains memory management for the both.

    kind regards,

    Jos
    Thanks, but I cannot find where I can actually influence how Java determines the C++ Heap Space. I do not need to reference JNI objects, the memory allocation is simply made by method deep down in the cpp code that does not have to do anything with arguments passed from Java to the dll.

Similar Threads

  1. Memory Allocation
    By zzpprk in forum Advanced Java
    Replies: 2
    Last Post: 03-16-2010, 01:14 AM
  2. Array memory allocation
    By number5isalive in forum Advanced Java
    Replies: 8
    Last Post: 10-14-2009, 08:04 AM
  3. Memory Allocation
    By kishan in forum New To Java
    Replies: 3
    Last Post: 09-19-2009, 05:47 PM
  4. Resource management allocation
    By jyothi.priyanka in forum New To Java
    Replies: 0
    Last Post: 04-04-2009, 01:25 PM
  5. Replies: 2
    Last Post: 08-21-2008, 07:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •