MemoryFailPoint(Int32) 생성자

정의

성공적으로 실행하는 데 필요한 메모리 양을 지정하여 MemoryFailPoint 클래스의 새 인스턴스를 초기화합니다.

public:
 MemoryFailPoint(int sizeInMegabytes);
public MemoryFailPoint (int sizeInMegabytes);
[System.Security.SecurityCritical]
public MemoryFailPoint (int sizeInMegabytes);
new System.Runtime.MemoryFailPoint : int -> System.Runtime.MemoryFailPoint
[<System.Security.SecurityCritical>]
new System.Runtime.MemoryFailPoint : int -> System.Runtime.MemoryFailPoint
Public Sub New (sizeInMegabytes As Integer)

매개 변수

sizeInMegabytes
Int32

필요한 메모리 크기(MB)입니다. 양수여야 합니다.

특성

예외

지정된 메모리 크기가 음수인 경우

게이트로 보호되는 코드의 실행을 시작하는 데 필요한 메모리가 부족한 경우

예제

다음 예제에서는 실행할 때 메서드에 필요한 메모리 양을 확인하는 방법을 보여 줍니다. 이 코드 예제는에 대해 제공 된 큰 예제의 일부는 MemoryFailPoint 클래스입니다.

private static int EstimateMemoryUsageInMB()
{
    int memUsageInMB = 0;

    long memBefore = GC.GetTotalMemory(true);
    int numGen0Collections = GC.CollectionCount(0);
    // Execute a test version of the method to estimate memory requirements.
    // This test method only exists to determine the memory requirements.
    ThreadMethod();
    // Includes garbage generated by the worker function.
    long memAfter = GC.GetTotalMemory(false);
    // If a garbage collection occurs during the measuring, you might need a greater memory requirement.
    Console.WriteLine("Did a GC occur while measuring?  {0}", numGen0Collections == GC.CollectionCount(0));
    // Set the field used as the parameter for the MemoryFailPoint constructor.
    long memUsage = (memAfter - memBefore);
    if (memUsage < 0)
    {
        Console.WriteLine("GC's occurred while measuring memory usage.  Try measuring again.");
        memUsage = 1 << 20;
    }

    // Round up to the nearest MB.
    memUsageInMB = (int)(1 + (memUsage >> 20));
    Console.WriteLine("Memory usage estimate: {0} bytes, rounded to {1} MB", memUsage, memUsageInMB);
    return memUsageInMB;
}

설명

애플리케이션에서 작업 항목을 처리 하는 데 사용 되는 메모리의 양은 알려지고 실험적으로 확인할 수 있습니다. 애플리케이션 요청을 처리 하는 데 필요한 메모리 양을 예측을 하려면 사용을 고려 합니다 GC.GetTotalMemory 작업 항목을 처리 하는 메서드를 호출 후 및 하기 전에 사용 가능한 메모리의 양을 결정 하는 방법입니다. 매개 변수의 MemoryFailPoint 값을 동적으로 결정하는 코드 예제는 클래스를 sizeInMegabytes 참조하세요.

적용 대상