ProcessModule.ModuleMemorySize 属性

定义

获取加载模块所需的内存量。

public:
 property int ModuleMemorySize { int get(); };
public int ModuleMemorySize { get; }
member this.ModuleMemorySize : int
Public ReadOnly Property ModuleMemorySize As Integer

属性值

模块占用的内存大小(以字节为单位)。

示例

下面的代码示例为 Notepad.exe 应用程序创建一个新进程。 代码循环访问 ProcessModuleCollection 类以获取集合中每个模块的 ProcessModule 对象。 ModuleNameModuleMemorySize 属性用于显示每个模块的模块名称和所需的内存量。

Process^ myProcess = gcnew Process;

// Get the process start information of notepad.
ProcessStartInfo^ myProcessStartInfo = gcnew 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( "{0} : {1}", myProcessModule->ModuleName, myProcessModule->ModuleMemorySize );
}
myProcessModule = myProcess->MainModule;

// Display the 'ModuleMemorySize' of the main module.
Console::WriteLine( "The process's main module's ModuleMemorySize is: {0}", myProcessModule->ModuleMemorySize );
myProcess->CloseMainWindow();
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();
}
Using myProcess As New Process()
    ' Get the process start information of notepad.
    Dim myProcessStartInfo As 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)
    Dim myProcessModule As ProcessModule
    ' Get all the modules associated with 'myProcess'.
    Dim myProcessModuleCollection As ProcessModuleCollection = myProcess.Modules
    Console.WriteLine("Module memory sizes of the modules associated " +
                      "with 'notepad' are:")
    ' Display the 'ModuleMemorySize' of each of the modules.
    Dim i As Integer
    For i = 0 To myProcessModuleCollection.Count - 1
        myProcessModule = myProcessModuleCollection(i)
        Console.WriteLine(myProcessModule.ModuleName + " : " +
                    myProcessModule.ModuleMemorySize.ToString())
    Next i
    ' 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.ToString())
    myProcess.CloseMainWindow()
End Using

注解

ModuleMemorySize 不包括模块运行后所做的任何额外内存分配;它仅包括模块文件中静态代码和数据的大小。

适用于