Speicherstatus

    • VB.NET

      Speicherstatus

      hier ist ein code zum abfragen des speicherstatus in einer konsolenanwendung:

      VB.NET-Quellcode

      1. Module Module1
      2. Sub Main()
      3. Dim s As String ' Zeichenfolge für die Ausgabe
      4. Dim strTPM, strAPM As String ' Total/Available Physical Memory
      5. Dim strTVM, strAVM As String ' Total/Available Virtual Memory
      6. Dim widthTotal As Integer ' Hilfsariable für die Ausrichtung der Ausgabe
      7. ' Speicherausstaung und - belegung ermitteln
      8. With My.Computer.Info
      9. strTPM = String.Format("{0:#,##0}", .TotalPhysicalMemory / 1024)
      10. strAPM = String.Format("{0:#,##0}", .AvailablePhysicalMemory / 1024)
      11. strTVM = String.Format("{0:#,##0}", .TotalVirtualMemory / 1024)
      12. strAVM = String.Format("{0:#,##0}", .AvailableVirtualMemory / 1024)
      13. End With
      14. 'Benötigte Spaltenbreite ermittlen
      15. If strTPM.Length > strTVM.Length Then
      16. widthTotal = strTPM.Length
      17. Else
      18. widthTotal = strTVM.Length
      19. End If
      20. 'Zeichenfolge für die Ausgabe zusammenstellen
      21. s = "Aktueller Speicherstatus (in KByte):" & vbCrLf & vbCrLf 'Titelzeile
      22. s &= " physikalisch: " & strTPM.PadLeft(widthTotal) ' Physikalischer Speicher
      23. s &= " (" & strAPM & " frei)" & vbCrLf
      24. s &= " virtuell :" & strTVM.PadLeft(widthTotal) ' Virtueller Speicher
      25. s &= " (" & strAVM & "frei)" & vbCrLf
      26. 'Ausgabe auf dem Bildschirm
      27. Console.WriteLine(s & vbCrLf)
      28. Console.ReadKey()
      29. End Sub
      30. End Module