ProcessModule.ModuleMemorySize 屬性

定義

取得載入模組所需的記憶體數量。

C#
public int ModuleMemorySize { get; }

屬性值

模組所佔用的記憶體大小 (以位元組為單位)。

範例

下列程式碼範例會建立 Notepad.exe 應用程式的新處理序。 程式碼會逐一查看 ProcessModuleCollection 類別以取得集合中每個模組的 ProcessModule 物件。 ModuleNameModuleMemorySize 屬性是用來顯示每個模組的模組名稱與所需記憶體數量。

C#
using (Process myProcess = new Process())
{
    // Get the process start information of notepad.
    ProcessStartInfo myProcessStartInfo = new ProcessStartInfo("notepad.exe");
    // Assign 'StartInfo' of notepad to 'StartInfo' of 'myProcess' object.
    myProcess.StartInfo = myProcessStartInfo;
    // Create a notepad.
    myProcess.Start();
    System.Threading.Thread.Sleep(1000);
    ProcessModule myProcessModule;
    // Get all the modules associated with 'myProcess'.
    ProcessModuleCollection myProcessModuleCollection = myProcess.Modules;
    Console.WriteLine("Module memory sizes of the modules associated "
        + "with 'notepad' are:");
    // Display the 'ModuleMemorySize' of each of the modules.
    for (int i = 0; i < myProcessModuleCollection.Count; i++)
    {
        myProcessModule = myProcessModuleCollection[i];
        Console.WriteLine(myProcessModule.ModuleName + " : "
            + myProcessModule.ModuleMemorySize);
    }
    // Get the main module associated with 'myProcess'.
    myProcessModule = myProcess.MainModule;
    // Display the 'ModuleMemorySize' of the main module.
    Console.WriteLine("The process's main module's ModuleMemorySize is: "
        + myProcessModule.ModuleMemorySize);
    myProcess.CloseMainWindow();
}

備註

ModuleMemorySize 不包含模組在執行之後所進行的任何額外記憶體配置;它只包括靜態程式碼的大小與模組檔案中的資料。

適用於

產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1