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 */
5256public 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
0 commit comments