다음을 통해 공유


방법: 장치 메모리 가져오기

업데이트: 2007년 11월

장치에 사용 가능한 메모리를 가져오려면 플랫폼 호출을 사용하여 네이티브 함수 GlobalMemoryStatusGetSystemMemoryDivision을 호출합니다.

예제

이 코드 예제에서는 다음을 정의합니다.

  • Windows Embedded CE에서 네이티브 메서드에 대한 플랫폼 호출 선언

  • 네이티브 메서드에 전달하거나 네이티브 메서드에서 받을 구조체

  • 사용 가능한 메서드를 표시하는 관리되는 메서드(ShowMemory)

Public Structure MEMORYSTATUS
    Public dwLength As UInt32
    Public dwMemoryLoad As UInt32
    Public dwTotalPhys As UInt32
    Public dwAvailPhys As UInt32
    Public dwTotalPageFile As UInt32
    Public dwAvailPageFile As UInt32
    Public dwTotalVirtual As UInt32
    Public dwAvailVirtual As UInt32
End Structure 

Public Declare Function GlobalMemoryStatus Lib "CoreDll.Dll" _
    (ByRef ms As MEMORYSTATUS) As Integer

Public Declare Function GetSystemMemoryDivision Lib "CoreDll.Dll" _
    (ByRef lpdwStorePages As UInt32, _
    ByRef ldpwRamPages As UInt32, _
    ByRef ldpwPageSize As UInt32) As Integer

Public Shared Sub ShowMemory()
    Dim storePages As UInt32
    Dim ramPages As UInt32
    Dim pageSize As UInt32
    Dim res As Integer = _
        GetSystemMemoryDivision(storePages, ramPages, pageSize)

    ' Call the native GlobalMemoryStatus method
    ' with the defined structure.
    Dim memStatus As New MEMORYSTATUS
    GlobalMemoryStatus(memStatus)

  ' Use a StringBuilder for the message box string.
    Dim MemoryInfo As New StringBuilder
    MemoryInfo.Append("Memory Load: " _
        & memStatus.dwMemoryLoad.ToString() & vbCrLf)
    MemoryInfo.Append("Total Physical: " _
        & memStatus.dwTotalPhys.ToString() & vbCrLf)
    MemoryInfo.Append("Avail Physical: " _
        & memStatus.dwAvailPhys.ToString() & vbCrLf)
    MemoryInfo.Append("Total Page File: " _
        & memStatus.dwTotalPageFile.ToString() & vbCrLf)
    MemoryInfo.Append("Avail Page File: " _
        & memStatus.dwAvailPageFile.ToString() & vbCrLf)
    MemoryInfo.Append("Total Virtual: " _
        & memStatus.dwTotalVirtual.ToString() & vbCrLf)
    MemoryInfo.Append("Avail Virtual: " _
        & memStatus.dwAvailVirtual.ToString() & vbCrLf)

    ' Show the available memory.
    MessageBox.Show(MemoryInfo.ToString())  

End Sub 
public struct MEMORYSTATUS
{
    public UInt32 dwLength;
    public UInt32 dwMemoryLoad;
    public UInt32 dwTotalPhys;
    public UInt32 dwAvailPhys;
    public UInt32 dwTotalPageFile;
    public UInt32 dwAvailPageFile;
    public UInt32 dwTotalVirtual;
    public UInt32 dwAvailVirtual;
}

[DllImport("CoreDll.dll")]
public static extern void GlobalMemoryStatus
(
    ref MEMORYSTATUS lpBuffer
);

[DllImport("CoreDll.dll")]
public static extern int GetSystemMemoryDivision
(
    ref UInt32 lpdwStorePages,
    ref UInt32 lpdwRamPages,
    ref UInt32 lpdwPageSize
);

public void ShowMemory()
{
    UInt32 storePages = 0;
    UInt32 ramPages = 0;
    UInt32 pageSize = 0;
    int res = GetSystemMemoryDivision(ref storePages, 
        ref ramPages, ref pageSize);

    // Call the native GlobalMemoryStatus method
    // with the defined structure.
    MEMORYSTATUS memStatus = new MEMORYSTATUS();
    GlobalMemoryStatus(ref memStatus);

    // Use a StringBuilder for the message box string.
    StringBuilder MemoryInfo = new StringBuilder();
    MemoryInfo.Append("Memory Load: " 
        + memStatus.dwMemoryLoad.ToString() + "\n");
    MemoryInfo.Append("Total Physical: " 
        + memStatus.dwTotalPhys.ToString() + "\n");
    MemoryInfo.Append("Avail Physical: " 
        + memStatus.dwAvailPhys.ToString() + "\n");
    MemoryInfo.Append("Total Page File: " 
        + memStatus.dwTotalPageFile.ToString() + "\n");
    MemoryInfo.Append("Avail Page File: " 
        + memStatus.dwAvailPageFile.ToString() + "\n");
    MemoryInfo.Append("Total Virtual: " 
        + memStatus.dwTotalVirtual.ToString() + "\n");
    MemoryInfo.Append("Avail Virtual: " 
        + memStatus.dwAvailVirtual.ToString() + "\n");

    // Show the available memory.
    MessageBox.Show(MemoryInfo.ToString());

}

코드 컴파일

이 예제에는 다음과 같은 네임스페이스에 대한 참조가 필요합니다.

참고 항목

작업

방법: 장치 ID 및 이름 가져오기

기타 리소스

.NET Compact Framework의 상호 운용성