catch (Throwable e) error
I am having two arrays, int[] pix and byte[] bytes, and I am inside a try loop with catch (Throwable e).
If I define the pix array too large (20 million),
pix = new int[20000000];
I end up with
catch (Throwable e).
If I define both arrays pretty large (15 million),
pix = new int[15000000];
byte = new byte[15000000];
I end up with
catch (Throwable e)
at the second array.
If I define both arrays smaller (10 million),
pix = new int[10000000];
byte = new byte[10000000];
everything is fine and there is no catch.
Why is this and how can I resolve it?
Thanks for looking at this!
What do you mean you "end up with" "catch (Throwable e)"?Do you mean that an exception is thrown, which is caught by that catch block?If so...you should actually look at the Throwable to see what it is.
It's a java.lang.OutOfMemoryError. Why is there this error and how can I resolve it?
It means you've run out of memory.You can increase the size of memory available to the JVM with command line options. Read the manual pages for java.exe for details.But you might also ask yourself whether you really need arrays that are megabytes long.
> It's a java.lang.OutOfMemoryError.
>
> Why is there this error and how can I resolve it?
Like the error says, you are out of memory.
You can increase the memory size with parameters on the "java" command - I do not remember the exact parameter off the top of my head but you can google for them.
jbisha at 2007-7-12 21:56:55 >

> But you might also ask yourself whether you really> need arrays that are megabytes long....nearly a gigabyte long...
Because the array whose element is the simple type as int, byte,char need the seriate memory. If your memory is enough, can set the parameter of jvm as " -vmargs -Xms256M -Xmx512M" through to the requirement of the program.
Thanks!Rather than setting the memory in the java command line, how can I do it in JBuilder?
Ok, I found out how to do this in JBuilder: In Run>Configurations>Edit at the VM parameters, I put
-Xms256M -Xmx512M
and it works!
Thanks again!
I am just wondering what's the maximum memory at Xmx I can set, and does it make the program slower when I set a higher Xmx memory?
Besides wondering what the maximum "maximum memory" is I can set, there is a problem.
The program only runs from JBuilder as many times as I like to run it, but it doesn't run from the .jar or the .exe file.
How can I set the memory so that it also works for the .jar and .exe file?
> I am just wondering what's the maximum memory at Xmx
> I can set, and does it make the program slower when I
> set a higher Xmx memory?
How much memory do you have?
Also what the hell are you doing? And learn to run Java programs outside of JBuilder please. It's not that hard.
The '-Xms256M -Xmx512M' is as same as the parameter of the 'java.exe' in the command line.
I have 0.99GB memory, but my program will be a product running on a lot of different machines.
What I am doing is I am developing a plugin for Photoshop written in Java, and the Java .exe file is called from C++. I need lots of memory for communicating the picture information from Photoshop to my program, which brings up its own window.
I like to use JBuilder, because it creates an executable for the PC and an executable for the Mac.
But why does the program only run from JBuilder and not from the .exe file?
Ok, I am calling the Java .exe from a C++ program.How can I set the -Xms256M -Xmx512M parameters in the C++ program?
Well, I can set the args[0] parameter of the main method in my Java program from my C++ program.But is it possible to set -vmargs -Xms256M -Xmx512M in the main method?
what the **** are you doing with arrays that large?
Ok, as I mentioned before, I have a plugin to Photoshop written in Java and connected to Photoshop's C++.
My plugin has to bring up its own window (since Photoshop doesn't allow to add to their Tools palette), it brings up the Photoshop picture and draws curves in a better way such as for tracing.
I am calling the Java program with ShellExecuteEx from the C++ program and I communicate the picture and the curves with file i/o. So the communication of the picture is what takes large arrays.
Where can I set the memory allocation in SHELLEXECUTEINFO? (I use lpParameters for setting the args[0] parameter of the main method in the Java program).
Assuming the arguments you are currently passing from the C++ prog look something like this
java.exeMyBigArrayProgramMyInputPicture.jpg
^ ^ ^
|| |
Java ExeYour Java main Class The args[0] param
you just add between java.exe and The main class the args
-Xms256M -Xmx512M
~Tim
The arguments I am currently passing from my C++ program to my Java program are simply picture size, zoom factor, scrolling information, etc, which I am passing with the lpParameters attribute of SHELLEXECUTEINFO. These arguments become the args[0] parameter in the main method of my Java program.
The array with the picture information would be too large for the args parameter in my Java program; so I am passing it in a file that I write in C++ and read in Java.
The only other thing I am passing from my C++ program to my Java program is the file name of the binary executable of my Java program, which I am passing with the lpFile attribute of SHELLEXECUTEINFO.
So what do you mean by going between java.exe and the main class?
By java.exe do you mean the executable of my Java program or the java command in the command prompt (in my C++ program I am not using the java command)?
Not being a C++ programmer (I have used it in the distant past), My suggestion/educated guess would be to have the -Xms -Xmx args be at the beginning of the lpParameters attribute. If I am not mistaken, the java exe will recognize them as vm args and parse them correctly.
ie:
//currently you have this, perhaps
LPCTSTR lpParam = "MyProgName <picSize> <otherInfo> <even more info>";
//then you would change it to something like this
LPCTSTR lpParam = "-Xmx256M -Xmx512M MyProgName <picSize> <otherInfo> <even more info>";
Trial and Error will give you the actual answer here, not I.
~Tim
EDIT: Sorry, I just noticed that you said binary exec of the java program. So, I missed that, I do not compile my java programs to a native executable (is this what you did?), so I could not help you. I was thinking more alongthe lines of the lpFile being the java.exe executable, and the lpParameters being teh main class file of the java program, followed by your additional parameters. My solution probably will not work for you if you do complie your java files into a native exe.
> So what do you mean by going between java.exe and the
> main class?
> By java.exe do you mean the executable of my Java
> program or the java command in the command prompt (in
> my C++ program I am not using the java command)?
You can run java in two different ways via C++.
1. Via a system call which creates a separate process.
2. Via JNI where java will run in the same process space as your application.
Passing arguments are different for both.
Note if you are doing 2 then you will probably end up with double the memory size in a single application since both are likely to have copies.
Well, I want to go away from using JNI (That actually caused memory leaks and problems for making a Mac port).So how do I translate my command prompt call to a ShellExecutEx call?
> So how do I translate my command prompt call to a> ShellExecutEx call?Just like you do on the command line....<java> <java command line options> <java class name> <options to class>
No, my line in the command prompt looks like this if the name of the Java executable is test.exe:
test.exe -vmargs -Xms256M -Xmx512M
Well, I was finally able to communicate this from my C++ program to my Java program by setting the lpParameters of SHELLEXECUTEINFO to
s, where
string str = "-vmargs -Xms256M -Xmx51\0";
const char *s = str.c_str().
However this only worked after I stopped communicating any other parameters with lpParameters by communicating the other ones with a file transfer.
> No, my line in the command prompt looks like this if
> the name of the Java executable is test.exe:
> test.exe -vmargs -Xms256M -Xmx512M
Then you are certainly not using the Sun VM. Nor I suspect that you are using any standard VM, but rather something that you created yourself. If so you need to determine how that thing passes parameters.
Well, for some reason,
if in my C++ program I pass the memory parameters:
-vmargs -Xms256M -Xmx51\0
when I call the Java binary executable (...W.exe),
the program works even if I communicate a large picture from C++ to Java,
and if in my C++ program I do not pass the memory paramters, the program doesn't work if I communicate a large picture from C++ to Java.
Does part of the Java VM get included in the Java executable?
Sigh....
What exactly is a "java executable"?
Normally in a java application there are two parts
1. The VM
2. The classes.
The VM is the VM. You provide parameters to it. Or you don't. If you don't then it doesn't use them.
Normally C++ would only apply to JNI which I believe you already said you aren't using. And if you are not using JNI then the fact that you are using C++ Is totally irrelevant because the only way you can 'run' java then is via another application (which you presumbably start in your C++ code). And it that case ALL that matters is how you start it.
And you would still be using a VM.
If you are not using a VM then no one here can help you because we use VMs not things created by you or someone else. And in that case you must figure it out yourself (if you created it) or ask the other person that created it.
Ok, In JBuilder 2006 I went to File>New>Archive>Executable JAR. This created 2 executables for Windows (one brings up the Command Prompt, the other one is called ...W.exe), and executables on Linux, Solaris, and Mac.
However, I just noticed that these executables still seem to need the Java JRE.
I now wonder, in what way are these executables different from the .jar file? Are they more difficult to reverse-engineer?
> Ok, In JBuilder 2006 I went to
> File>New>Archive>Executable JAR. This created 2
> executables for Windows (one brings up the Command
> Prompt, the other one is called ...W.exe), and
> executables on Linux, Solaris, and Mac.
>
Finally....
> However, I just noticed that these executables still
> seem to need the Java JRE.
>
> I now wonder, in what way are these executables
> different from the .jar file?
For starters a jar file is not an exe.
> Are they more
> difficult to reverse-engineer?
Huh? You want to reverse the exe? Then you need a decompiler. I suspect you will find that it isn't all that complicated though.
I would also suspect that you will find documentation somewhere that describes how to add the necessary options to the exe either as part of the compilation/construction or on the command line itself.
But that is ALL specific to the tool you are using and has nothing to do with java in general.