public long estimateImageFileSize() { if ( -1 == depth ) return IJ.maxMemory() / 2; return (long) (width * height * depth * 4); }
int getAvailableMemory() { long max = IJ.maxMemory(); if (max==0) return -1; long inUse = IJ.currentMemory(); long available = max - inUse; return (int)((available+524288L)/1048576L); } }
int getAvailableMemory() { long max = IJ.maxMemory(); if (max==0) return -1; long inUse = IJ.currentMemory(); long available = max - inUse; return (int)((available+524288L)/1048576L); } }
/** Recover from an OutOfMemoryError: release 1/2 of all memory AND execute the garbage collector. */ public void recoverOOME() { releaseToFit(IJ.maxMemory() / 2); long start = System.currentTimeMillis(); long end = start; final long startmem = IJ.currentMemory(); for (int i=0; i<3; i++) { System.gc(); Thread.yield(); end = System.currentTimeMillis(); if (end - start > 2000) break; // garbage collection catched and is running. if (IJ.currentMemory() < startmem) break; start = end; } }
/** Runs the garbage collector and returns a string something like "64K of 256MB (25%)" that shows how much of the available memory is in use. This is the string displayed when the user clicks in the status bar. */ public static String freeMemory() { long inUse = currentMemory(); String inUseStr = inUse<10000*1024?inUse/1024L+"K":inUse/1048576L+"MB"; String maxStr=""; long max = maxMemory(); if (max>0L) { double percent = inUse*100/max; maxStr = " of "+max/1048576L+"MB ("+(percent<1.0?"<1":d2s(percent,0)) + "%)"; } return inUseStr + maxStr; }
/** Runs the garbage collector and returns a string something like "64K of 256MB (25%)" that shows how much of the available memory is in use. This is the string displayed when the user clicks in the status bar. */ public static String freeMemory() { long inUse = currentMemory(); String inUseStr = inUse<10000*1024?inUse/1024L+"K":inUse/1048576L+"MB"; String maxStr=""; long max = maxMemory(); if (max>0L) { double percent = inUse*100/max; maxStr = " of "+max/1048576L+"MB ("+(percent<1.0?"<1":d2s(percent,0)) + "%)"; } return inUseStr + maxStr; }
/** If the number of minimally free memory bytes (100 Mb times the number of CPU cores) is too low for your (giant) images, set it to a larger value here. */ public static void setDesirableMinFreeBytes(final long n_bytes) { long f = computeDesirableMinFreeBytes(); final long max = IJ.maxMemory(); if (n_bytes < f) { Utils.logAll("Refusing to use " + n_bytes + " as the desirable amount of free memory bytes,\n considering the lower limit at " + f); } else if (n_bytes > max) { Utils.logAll("Refusing to use a number of minimally free memory bytes larger than max_memory " + max); } else { if (n_bytes > max / 2) { Utils.logAll("WARNING you are setting a value of minimally free memory bytes larger than half the maximum memory."); } f = n_bytes; } MIN_FREE_BYTES = f; Utils.logAll("Using min free bytes " + MIN_FREE_BYTES + " (max memory: " + max + ")"); }
{interp.getParens(); return ""+IJ.currentMemory();} else if (name.equals("maxMemory")) {interp.getParens(); return ""+IJ.maxMemory();} else if (name.equals("getToolName")) {interp.getParens(); return ""+IJ.getToolName();}
{interp.getParens(); return ""+IJ.currentMemory();} else if (name.equals("maxMemory")) {interp.getParens(); return ""+IJ.maxMemory();} else if (name.equals("getToolName")) {interp.getParens(); return ""+IJ.getToolName();}
void changeMemoryAllocation() { IJ.maxMemory(); // forces IJ to cache old limit int max = (int)(getMemorySetting()/1048576L); boolean unableToSet = max==0;
void changeMemoryAllocation() { IJ.maxMemory(); // forces IJ to cache old limit int max = (int)(getMemorySetting()/1048576L); boolean unableToSet = max==0;
y += 18; ip.drawString(text[4], x(text[4],ip,max), y); if (IJ.maxMemory()>0L) { y += 18; ip.drawString(text[5], x(text[5],ip,max), y);
final long ijMaxMemory = IJ.maxMemory(); final int numCellCreatorThreads = Math.max( 1, PluginHelper.numThreads() - 1 ); final LoopbackHeuristic loopbackHeuristic = new LoopbackHeuristic()
y += 18; ip.drawString(text[4], x(text[4],ip,max), y); if (IJ.maxMemory()>0L) { y += 18; ip.drawString(text[5], x(text[5],ip,max), y);
if (size > IJ.maxMemory() * 0.9) { final YesNoCancelDialog yn = new YesNoCancelDialog(IJ.getInstance(), "WARNING", "The resulting stack of flat images is too large to fit in memory.\nChoose a directory to save the slices as an image sequence?"); if (yn.yesPressed()) {
String size2 = size/(1024*1024)+"MB ("+width+"x"+height+"x"+nSlices+")"; if ((options&CHECK_AVAILABLE_MEMORY)!=0) { long max = IJ.maxMemory(); // - 100*1024*1024; if (max>0) { long inUse = IJ.currentMemory();
String size2 = size/(1024*1024)+"MB ("+width+"x"+height+"x"+nSlices+")"; if ((options&CHECK_AVAILABLE_MEMORY)!=0) { long max = IJ.maxMemory(); // - 100*1024*1024; if (max>0) { long inUse = IJ.currentMemory();