Skip to content

Commit f46fe2b

Browse files
committed
adding options for directly altering the memory setting
1 parent 3467a0c commit f46fe2b

10 files changed

Lines changed: 140 additions & 39 deletions

File tree

app/Preferences.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
* This class no longer uses the Properties class, since
4949
* properties files are iso8859-1, which is highly likely to
5050
* be a problem when trying to save sketch folders and locations.
51+
* <p>
52+
* This is very poorly put together, that the prefs panel and the
53+
* actual prefs i/o is part of the same code. But there hasn't yet
54+
* been a compelling reason to bother with the separation.
5155
*/
5256
public class Preferences {
5357

@@ -112,8 +116,9 @@ public class Preferences {
112116
JCheckBox sketchPromptBox;
113117
JCheckBox sketchCleanBox;
114118
JCheckBox externalEditorBox;
119+
JCheckBox memoryOverrideBox;
120+
JTextField memoryField;
115121
JCheckBox checkUpdatesBox;
116-
117122
JTextField fontSizeField;
118123

119124

@@ -303,6 +308,20 @@ public void actionPerformed(ActionEvent e) {
303308
top += d.height + GUI_BETWEEN;
304309

305310

311+
// [ ] Set maximum available memory to [______] MB
312+
313+
Container memoryBox = Box.createHorizontalBox();
314+
memoryOverrideBox = new JCheckBox("Set maximum available memory to ");
315+
memoryBox.add(memoryOverrideBox);
316+
memoryField = new JTextField(4);
317+
memoryBox.add(memoryField);
318+
memoryBox.add(new JLabel(" MB"));
319+
pain.add(memoryBox);
320+
d = memoryBox.getPreferredSize();
321+
memoryBox.setBounds(left, top, d.width, d.height);
322+
top += d.height + GUI_BETWEEN;
323+
324+
306325
// [ ] Use external editor
307326

308327
externalEditorBox = new JCheckBox("Use external editor");
@@ -476,6 +495,49 @@ public void applyFrame() {
476495
setBoolean("editor.external", externalEditorBox.isSelected());
477496
setBoolean("update.check", checkUpdatesBox.isSelected());
478497

498+
setBoolean("run.options.memory", memoryOverrideBox.isSelected());
499+
int memoryMin = Preferences.getInteger("run.options.memory.initial");
500+
int memoryMax = Preferences.getInteger("run.options.memory.maximum");
501+
try {
502+
memoryMax = Integer.parseInt(memoryField.getText().trim());
503+
// make sure memory setting isn't too small
504+
if (memoryMax < memoryMin) memoryMax = memoryMin;
505+
setInteger("run.options.memory.maximum", memoryMax);
506+
} catch (NumberFormatException e) {
507+
System.err.println("Ignoring bad memory setting");
508+
}
509+
510+
/*
511+
linux
512+
% java -Xmx3000m
513+
Error occurred during initialization of VM
514+
Could not reserve enough space for object heap
515+
fry@pooserve:~
516+
% java -Xmx5000m
517+
Invalid maximum heap size: -Xmx5000m
518+
Could not create the Java virtual machine.
519+
520+
macosx
521+
: java -Xmx3g
522+
Error occurred during initialization of VM
523+
Could not reserve enough space for object heap
524+
Trace/BPT trap
525+
: java -Xmx5g
526+
Invalid maximum heap size: -Xmx5g
527+
The specified size exceeds the maximum representable size.
528+
Could not create the Java virtual machine.
529+
530+
// was gonna use this to check memory settings,
531+
// but it quickly gets much too messy
532+
if (getBoolean("run.options.memory")) {
533+
Process process = Runtime.getRuntime().exec(new String[] {
534+
"java", "-Xms" + memoryMin + "m", "-Xmx" + memoryMax + "m"
535+
});
536+
processInput = new SystemOutSiphon(process.getInputStream());
537+
processError = new MessageSiphon(process.getErrorStream(), this);
538+
}
539+
*/
540+
479541
String newSizeText = fontSizeField.getText();
480542
try {
481543
int newSize = Integer.parseInt(newSizeText.trim());
@@ -502,6 +564,9 @@ public void showFrame(Editor editor) {
502564
externalEditorBox.setSelected(getBoolean("editor.external"));
503565
checkUpdatesBox.setSelected(getBoolean("update.check"));
504566

567+
memoryOverrideBox.setSelected(getBoolean("run.options.memory"));
568+
memoryField.setText(get("run.options.memory.maximum"));
569+
505570
dialog.show();
506571
}
507572

app/Runner.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public void startPresenting() throws Exception {
110110
}
111111
}
112112

113+
if (Preferences.getBoolean("run.options.memory")) {
114+
params.add("-Xms" + Preferences.get("run.options.memory.initial") + "m");
115+
params.add("-Xmx" + Preferences.get("run.options.memory.maximum") + "m");
116+
}
117+
113118
params.add("-Djava.library.path=" +
114119
sketch.libraryPath +
115120
File.pathSeparator +
@@ -181,6 +186,12 @@ public void startExternalRuntime(Point windowLocation) throws Exception {
181186
}
182187
}
183188
}
189+
190+
if (Preferences.getBoolean("run.options.memory")) {
191+
params.add("-Xms" + Preferences.get("run.options.memory.initial") + "m");
192+
params.add("-Xmx" + Preferences.get("run.options.memory.maximum") + "m");
193+
}
194+
184195
// sketch.libraryPath might be ""
185196
// librariesClassPath will always have sep char prepended
186197
params.add("-Djava.library.path=" +
@@ -203,7 +214,7 @@ public void startExternalRuntime(Point windowLocation) throws Exception {
203214

204215
String command[] = new String[params.size()];
205216
params.copyInto(command);
206-
//PApplet.println(command);
217+
PApplet.println(command);
207218

208219
process = Runtime.getRuntime().exec(command);
209220
processInput = new SystemOutSiphon(process.getInputStream());

app/Sketch.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,12 @@ protected String build(String buildPath, String suggestedClassName)
13701370
libraryPath = "";
13711371
}
13721372

1373+
// if the memory options are set, then use an external runtime
1374+
// so that the setting can always be honored.
1375+
if (Preferences.getBoolean("run.options.memory")) {
1376+
externalRuntime = true;
1377+
}
1378+
13731379
// if 'data' folder is large, set to external runtime
13741380
if (dataFolder.exists() &&
13751381
Base.calcFolderSize(dataFolder) > 768 * 1024) { // if > 768k
@@ -2388,7 +2394,13 @@ public boolean exportApplication(int exportPlatform) throws Exception {
23882394
File argsFile = new File(destFolder + "/lib/args.txt");
23892395
PrintStream ps = new PrintStream(new FileOutputStream(argsFile));
23902396

2391-
ps.println(Preferences.get("run.options"));
2397+
ps.print(Preferences.get("run.options") + " ");
2398+
if (Preferences.getBoolean("run.options.memory")) {
2399+
ps.print("-Xms" + Preferences.get("run.options.memory.initial") + "m ");
2400+
ps.print("-Xmx" + Preferences.get("run.options.memory.maximum") + "m ");
2401+
}
2402+
ps.println();
2403+
23922404
ps.println(this.name);
23932405
ps.println(exportClassPath);
23942406

build/shared/lib/preferences.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ run.present.bgcolor = #666666
187187
# if you hose this and can't run things, it's your own durn fault
188188
run.options =
189189

190+
# settings for the -XmsNNNm and -XmxNNNm command line option
191+
run.options.memory = false
192+
run.options.memory.initial = 64
193+
run.options.memory.maximum = 256
194+
190195
# example of increasing the memory size for applets run externally
191196
#run.options = -Xms128m -Xmx1024m
192197

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#Sun Sep 17 22:12:07 EDT 2006
1+
#Tue Sep 19 19:48:27 EDT 2006
22
eclipse.preferences.version=1
3+
formatter_profile=_two spaces no tabs
34
formatter_settings_version=10
45
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8"?><templates/>

core/src/processing/core/PConstants.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ public interface PConstants {
289289
static final int DISABLE_DEPTH_TEST = 5;
290290
static final int NO_FLYING_POO = 6;
291291
static final int ENABLE_DEPTH_SORT = 7;
292+
static final int DISABLE_ERROR_REPORT = 8;
292293

293-
static final int HINT_COUNT = 8;
294+
static final int HINT_COUNT = 9;
294295

295296

296297
//////////////////////////////////////////////////////////////

opengl/library/opengl.jar

12 Bytes
Binary file not shown.

opengl/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,33 +2397,32 @@ private final float min(float a, float b) {
23972397
* throw an GL_INVALID_OPERATION error.
23982398
*/
23992399
public void report(String where) {
2400-
//if (true) return;
2401-
2402-
int err = gl.glGetError();
2403-
if (err == 0) {
2404-
return;
2405-
//System.out.println("no error");
2406-
} else {
2407-
System.out.print("GL_ERROR at " + where + ": ");
2408-
System.out.print(PApplet.hex(err, 4) + " ");
2409-
switch (err) {
2410-
case 0x0500: System.out.print("GL_INVALID_ENUM"); break;
2411-
case 0x0501: System.out.print("GL_INVALID_VALUE"); break;
2412-
case 0x0502: System.out.print("GL_INVALID_OPERATION"); break;
2413-
case 0x0503: System.out.print("GL_STACK_OVERFLOW"); break;
2414-
case 0x0504: System.out.print("GL_STACK_UNDERFLOW"); break;
2415-
case 0x0505: System.out.print("GL_OUT_OF_MEMORY"); break;
2416-
default: System.out.print("UNKNOWN");
2400+
if (!hints[DISABLE_ERROR_REPORT]) {
2401+
int err = gl.glGetError();
2402+
if (err != 0) {
2403+
System.out.print("GL_ERROR at " + where + ": ");
2404+
System.out.print(PApplet.hex(err, 4) + " ");
2405+
switch (err) {
2406+
case 0x0500: System.out.print("GL_INVALID_ENUM"); break;
2407+
case 0x0501: System.out.print("GL_INVALID_VALUE"); break;
2408+
case 0x0502: System.out.print("GL_INVALID_OPERATION"); break;
2409+
case 0x0503: System.out.print("GL_STACK_OVERFLOW"); break;
2410+
case 0x0504: System.out.print("GL_STACK_UNDERFLOW"); break;
2411+
case 0x0505: System.out.print("GL_OUT_OF_MEMORY"); break;
2412+
default: System.out.print("UNKNOWN");
2413+
}
2414+
System.out.println();
24172415
}
2418-
System.out.println();
24192416
}
24202417
}
24212418

2422-
//GL will do the clipping for us
2419+
2420+
//GL will do the clipping for us
24232421
protected void add_line(int a, int b) {
24242422
add_line_no_clip(a, b);
24252423
}
24262424

2425+
24272426
// GL will do the clipping for us
24282427
protected void add_triangle(int a, int b, int c) {
24292428
add_triangle_no_clip(a, b, c);

pdf/library/pdf.jar

0 Bytes
Binary file not shown.

todo.txt

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ X move 'how do i create large images' here
5353
X createGraphics with PDF, using dispose() to clear the thing
5454
X calling nextPage()
5555
_ under the memory section, getting free/total memory
56-
_ long mem = Runtime.getRuntime().freeMemory()
57-
_ long mem = Runtime.getRuntime().totalMemory()
56+
_ long allocated = Runtime.getRuntime().totalMemory() (-Xms usually)
57+
_ long allocatedButFree = Runtime.getRuntime().freeMemory() (-Xms minus used)
58+
_ long maximum = Runtime.getRuntime().maxMemory() (-Xmx setting)
5859

5960
mac faq
6061
X windows, may need to install new version of video drivers
@@ -91,11 +92,25 @@ _ search for ALL in the bugs db turns up:
9192
http://dev.processing.org/bugs/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=RESOLVED&bug_status=VERIFIED&bug_status=CLOSED
9293
_ add note to bugs db asking to please use archive sketch and attach
9394

94-
faq / general
95+
faq / advanced
9596
_ the source code to the libs are included
9697
_ this makes them easy to modify (in another app)
9798
_ or you can remove the package statements and embed them
9899
_ serial is a little trickier since you'd have to put stuff in code/
100+
_ making things fast with pixel operations
101+
_ jai handles setting image size
102+
_ PNGEncodeParam png = PNGEncodeParam.getDefaultEncodeParam(bufImage);
103+
_ png.setPhysicalDimension(round(dpi*39.370079), round(dpi*39.370079), 1);
104+
_ JAI.create("filestore", bufImage, filename+".png", "PNG");
105+
_ also an example of setting the jpeg compression
106+
_ add something about getting a bufferedimage from a PGraphics
107+
_ maybe this should be a method?
108+
_ how to upload an image to a server
109+
110+
faq / platforms
111+
_ add notes about running processing on various platforms
112+
_ directions for rebuilding jikes, etc (where is this?)
113+
_ and then link to posts on the discourse site about how to do it
99114

100115
faq / export
101116
X exporting applets
@@ -107,20 +122,10 @@ _ notes about setting key=0 to catch ESC
107122
_ also size(screen.width, screen.height);
108123
_ maybe make a section in installations with p5
109124
_ exporting applications
110-
_ including the java subfolder with exported applications
125+
_ possible to include a java subfolder with exported applications
111126
_ this means no need to install an additional java vm
112127
_ or an option to include the 'java' folder on windows/linux with export
113-
114-
faq / images
115-
_ making things fast with pixel operations
116-
_ jai handles setting image size
117-
_ PNGEncodeParam png = PNGEncodeParam.getDefaultEncodeParam(bufImage);
118-
_ png.setPhysicalDimension(round(dpi*39.370079), round(dpi*39.370079), 1);
119-
_ JAI.create("filestore", bufImage, filename+".png", "PNG");
120-
_ also an example of setting the jpeg compression
121-
_ add something about getting a bufferedimage from a PGraphics
122-
_ maybe this should be a method?
123-
_ how to upload an image to a server
128+
_ on unix machines it's also possible to use a symlink
124129

125130
o menu weirdness (benelek)
126131
o when you've got a menu open, move a cursor over the text area
@@ -901,6 +906,8 @@ LIBRARIES / Video
901906

902907
_ need to add resize method to camera capture
903908
_ http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1150227643
909+
_ need to prevent multiple QTSession open or close
910+
_ static method shared across the lib, or some such
904911
_ capture.settings() changes size of capture
905912
_ http://dev.processing.org/bugs/show_bug.cgi?id=366
906913
_ reading movie is really really slow (2-3 fps)

0 commit comments

Comments
 (0)