Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4335914

RFE: Runtime should give max system memory, not just total

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • hotspot
    • beta
    • generic
    • generic



      Name: rlT66838 Date: 05/04/2000


      java version "1.3.0rc3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc3-Z)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, mixed mode)

      Since the amount of total memory
      (as reported by java.lang.Runtime.totalMemory())
      can change, it would be good if the Runtime also
      returned the maximum amount of memory.

      An appropriate algorithm might look like:

      Assume we have a function long absMaxMem() which returns the absolute maximum
      size of the VM (for instance, from the -Xm flag, or from system memory if the
      VM can grow without limit). Also assume there is a function long freeSysMem(),
      which returns the currently free amount of system memory.

      long Runtime.maxMemory()
      {
         long maxMem = absMaxMem();
         long freeMem = freeSysMem();

         return ((maxMem > freeMem) ? freeMem : maxMem);
      }

      There just isn't any reasonable way to know if you can read in a large file
      unless you know how big the VM can get. Of course, if you could catch
      OutOfMemoryError that wouln't be as big a deal, 'cause you could clean up after
      the file if it didn't completely read in.
      (Review ID: 104479)
      ======================================================================

            sgrarupsunw Steffen Grarup (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: