Runtime.getRuntime()...

Schaaaf

Bekanntes Mitglied
Hallo,

ich habe forlgenden Code gefunden :

Java:
...
long total=Runtime.getRuntime().totalMemory();
long free=Runtime.getRuntime().freeMemory();
long max=Runtime.getRuntime().maxMemory();

System.out.println("Total memory :" +total);
System.out.println("Free memory :" +free);
System.out.println("Max memory :" +max);
System.out.println(total-free);
System.out.println(free+(max-total));
...

Nun meine Frage:
Was für ein Ergebnis bekomme ich für
Java:
System.out.println(total-free);
und
Java:
System.out.println(free+(max-total));
?
 
die Frage ist keine richtige Frage,
weder weiß jemand welche exakten Arbeitspeicher-Zahlen bei dir rauskommen,
noch läßt sich eine Programmausgabe philosophisch als etwas bestimmtes klassifizieren

oder mal anders:
wenn in eine Kiste 100 Bauklötze passen und 30 schon drin ist, dann kennst du doch gewiss die Bedeutung der Zahl 70?
 
die Frage liese sich auch einfach mittels Blick in die Doku beantworten:
API Doku hat gesagt.:
freeMemory
public long freeMemory()Returns the amount of free memory in the Java Virtual Machine. Calling the gc method may result in increasing the value returned by freeMemory.

Returns:
an approximation to the total amount of memory currently available for future allocated objects, measured in bytes.

--------------------------------------------------------------------------------

totalMemory
public long totalMemory()Returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.


Returns:
the total amount of memory currently available for current and future objects, measured in bytes.

--------------------------------------------------------------------------------

maxMemory
public long maxMemory()Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned.


Returns:
the maximum amount of memory that the virtual machine will attempt to use, measured in bytes
Since:
1.4
 
Bauklötze mochtest du ja nicht, dann ein Haus:
Höhe gegeben, Höhe Dach gegeben, was ist Höhe - Höhe Dach?
würdest du das auch im Forum fragen, gar keine Lust zum Nachdenken?

noch ein Tipp:
free+(max-total)
ist umgeformt max - (total-free), also max wie das was Zeile 9 ist, was du nun ja schon erfahren hast..
 
Zuletzt bearbeitet von einem Moderator:

Zurück
Oben