Nutzung des Arbeitspeichers?



  • Ich hätte gern gewusst ob es eine möglichkeit gibt, den aktuellen stand der speicherausnutzung zu erfahren. da ich beim start meiner anwendung gern wissen würde ob der verfügbare arbeitsspeicher ausreicht.





  • das is ja perfekt.... Danke! 😮



  • "Die Anweisung in "0x77e72f22" verweißt auf Speicher in "0x07e4d000". Der Vorgang "read" konnte nicht auf dem Speicher durhcgeführt werden...

    mh ja ok so richtig funktionierts dann doch nicht ^^



  • Dann hast du die Funktion wohl nicht richtig aufgerufen:

    MEMORYSTATUS memoryStatus;
    GlobalMemoryStatus(&memoryStatus);
    


  • MEMORYSTATUS stat;
    GlobalMemoryStatus(&stat);
    if( stat.dwTotalPhys - stat.dwAvailPhys < 16834){
        MessageBox(GetActiveWindow(), "Es ist nicht mehr viel Arbeitsspeicher vorhanden.\nNeustart empfohlen", "Warnung!", MB_OK | MB_ICONERROR);
    }
    

    doch doch genau so. windows.h is auch eingebunden 😕



  • Funktioniert denn das Beispiel aus der MSDN auch nicht (obwohl die das da genauso machen wie Du)?

    //  Sample output:
    //  The MemoryStatus structure is 32 bytes long.
    //  It should be 32.
    //  78 percent of memory is in use.
    //  There are   65076 total Kbytes of physical memory.
    //  There are   13756 free Kbytes of physical memory.
    //  There are  150960 total Kbytes of paging file.
    //  There are   87816 free Kbytes of paging file.
    //  There are  1fff80 total Kbytes of virtual memory.
    //  There are  1fe770 free Kbytes of virtual memory.
    
    #include <windows.h>
    
    // Use to change the divisor from Kb to Mb.
    
    #define DIV 1024
    // #define DIV 1
    
    char *divisor = "K";
    // char *divisor = "";
    
    // Handle the width of the field in which to print numbers this way to
    // make changes easier. The asterisk in the print format specifier
    // "%*ld" takes an int from the argument list, and uses it to pad and
    // right-justify the number being formatted.
    #define WIDTH 7
    
    void main(int argc, char *argv[])
    {
      MEMORYSTATUS stat;
    
      GlobalMemoryStatus (&stat);
    
      printf ("The MemoryStatus structure is %ld bytes long.\n",
              stat.dwLength);
      printf ("It should be %d.\n", sizeof (stat));
      printf ("%ld percent of memory is in use.\n",
              stat.dwMemoryLoad);
      printf ("There are %*ld total %sbytes of physical memory.\n",
              WIDTH, stat.dwTotalPhys/DIV, divisor);
      printf ("There are %*ld free %sbytes of physical memory.\n",
              WIDTH, stat.dwAvailPhys/DIV, divisor);
      printf ("There are %*ld total %sbytes of paging file.\n",
              WIDTH, stat.dwTotalPageFile/DIV, divisor);
      printf ("There are %*ld free %sbytes of paging file.\n",
              WIDTH, stat.dwAvailPageFile/DIV, divisor);
      printf ("There are %*lx total %sbytes of virtual memory.\n",
              WIDTH, stat.dwTotalVirtual/DIV, divisor);
      printf ("There are %*lx free %sbytes of virtual memory.\n",
              WIDTH, stat.dwAvailVirtual/DIV, divisor);
    }
    


  • Btw: schonmal was von der Auslagerungsdatei gehört?! Windows lagert doch im Normalfall aus, und du bekommst (wenn Windows das für sinnvoll hält) Speicher im RAM 🙂



  • Das ist mir schon klar das windows das auslagert 😉
    Jedoch ist das Teil meiner Aufgabe und wenn das so gefordert ist dann sollte ich das auch bringen oder? 😃

    aber danke, hab das Problem gefunden!



  • sToRkka schrieb:

    Das ist mir schon klar das windows das auslagert 😉
    Jedoch ist das Teil meiner Aufgabe und wenn das so gefordert ist dann sollte ich das auch bringen oder? 😃

    Ja, ist schon recht - wollte das nur eben nicht unerwähnt lassen. Denn im Normalfall macht es eben nicht viel Sinn, Windows bei der Speicherbelegung reinzureden. Aber wenn das eben deine Aufgabe ist...

    sToRkka schrieb:

    aber danke, hab das Problem gefunden!

    Es wäre noch nett, wenn du für die Nachwelt mitteilen würdest, woran es gelegen hat 🙂



  • Der Fehler lag in einem ganz anderen Teil des Projektes. Also das was ich hinzugefügt habe war schon richtig, da der Fehler vorher auch schon da war nur noch nicht ausgelöst wurde da ich die Funktion bis dahin noch nicht gebraucht hatte, jedoch nach der Änderung schon *g* verständlich?


Anmelden zum Antworten