英語で読む

次の方法で共有


Process.PeakWorkingSet64 プロパティ

定義

関連付けられたプロセスによって使用される物理メモリの最大量をバイト数として取得します。

public long PeakWorkingSet64 { get; }
[System.Runtime.InteropServices.ComVisible(false)]
public long PeakWorkingSet64 { get; }

プロパティ値

プロセスの開始以降、関連付けられたプロセスに割り当てられた物理メモリの最大量 (バイト単位)。

属性

次のコード例では、メモ帳アプリケーションのインスタンスを開始します。 次に、この例では、関連付けられているプロセスのさまざまなプロパティを取得して表示します。 この例では、プロセスがいつ終了したかを検出し、終了コードとピーク メモリ統計を表示します。

using System;
using System.Diagnostics;

namespace ProcessSample
{
    class ProcessMonitorSample
    {
        public static void Main()
        {
            // Define variables to track the peak
            // memory usage of the process.
            long peakPagedMem   = 0,
                 peakWorkingSet = 0,
                 peakVirtualMem = 0;

            // Start the process.
            using (Process myProcess = Process.Start("NotePad.exe"))
            {
                // Display the process statistics until
                // the user closes the program.
                do
                {
                    if (!myProcess.HasExited)
                    {
                        // Refresh the current process property values.
                        myProcess.Refresh();

                        Console.WriteLine();

                        // Display current process statistics.

                        Console.WriteLine($"{myProcess} -");
                        Console.WriteLine("-------------------------------------");

                        Console.WriteLine($"  Physical memory usage     : {myProcess.WorkingSet64}");
                        Console.WriteLine($"  Base priority             : {myProcess.BasePriority}");
                        Console.WriteLine($"  Priority class            : {myProcess.PriorityClass}");
                        Console.WriteLine($"  User processor time       : {myProcess.UserProcessorTime}");
                        Console.WriteLine($"  Privileged processor time : {myProcess.PrivilegedProcessorTime}");
                        Console.WriteLine($"  Total processor time      : {myProcess.TotalProcessorTime}");
                        Console.WriteLine($"  Paged system memory size  : {myProcess.PagedSystemMemorySize64}");
                        Console.WriteLine($"  Paged memory size         : {myProcess.PagedMemorySize64}");

                        // Update the values for the overall peak memory statistics.
                        peakPagedMem   = myProcess.PeakPagedMemorySize64;
                        peakVirtualMem = myProcess.PeakVirtualMemorySize64;
                        peakWorkingSet = myProcess.PeakWorkingSet64;

                        if (myProcess.Responding)
                        {
                            Console.WriteLine("Status = Running");
                        }
                        else
                        {
                            Console.WriteLine("Status = Not Responding");
                        }
                    }
                }
                while (!myProcess.WaitForExit(1000));

                Console.WriteLine();
                Console.WriteLine($"  Process exit code          : {myProcess.ExitCode}");

                // Display peak memory statistics for the process.
                Console.WriteLine($"  Peak physical memory usage : {peakWorkingSet}");
                Console.WriteLine($"  Peak paged memory usage    : {peakPagedMem}");
                Console.WriteLine($"  Peak virtual memory usage  : {peakVirtualMem}");
            }
        }
    }
}

注釈

このプロパティによって返される値は、プロセスが開始されてから使用されるワーキング セット メモリの最大サイズをバイト単位で表します。 プロセスのワーキング セットとは、プロセスが物理 RAM メモリ内で現在参照できるメモリ ページのセットです。 これらのページは常駐しており、ページ フォールトをトリガーすることなくアプリケーションから使用できます。

ワーキング セットには、共有データとプライベート データの両方が含まれます。 共有データには、プロセス モジュールとシステム ライブラリからの命令を含め、プロセスが実行するすべての命令を含むページが含まれます。

このプロパティは、32 ビット プロセッサまたは 64 ビット プロセッサを搭載したコンピューターでのメモリ使用量を監視するために使用できます。 プロパティの値は、プロセスの Working Set Peak パフォーマンス カウンターと同じです。

適用対象

製品 バージョン
.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 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

こちらもご覧ください