GC.TryStartNoGCRegion 方法

定義

嘗試在執行關鍵路徑期間,禁止記憶體回收。Attempts to disallow garbage collection during the execution of a critical path.

多載

TryStartNoGCRegion(Int64)

嘗試在有指定數量記憶體可用時,於執行關鍵路徑期間,禁止記憶體回收。Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available.

TryStartNoGCRegion(Int64, Boolean)

嘗試在有指定數量記憶體可用時,於執行關鍵路徑期間,禁止記憶體回收,並控制在最初沒有足夠的記憶體可用時,記憶體回收行程是否執行完全封鎖記憶體回收。Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available, and controls whether the garbage collector does a full blocking garbage collection if not enough memory is initially available.

TryStartNoGCRegion(Int64, Int64)

嘗試在大型物件堆積與小型物件堆積有指定數量記憶體可用時,於執行關鍵路徑期間,禁止記憶體回收。Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available for the large object heap and the small object heap.

TryStartNoGCRegion(Int64, Int64, Boolean)

嘗試在大型物件堆積與小型物件堆積有指定數量記憶體可用時,於執行關鍵路徑期間,禁止記憶體回收,並控制在最初沒有足夠的記憶體可用時,記憶體回收行程是否執行完全封鎖記憶體回收。Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available for the large object heap and the small object heap, and controls whether the garbage collector does a full blocking garbage collection if not enough memory is initially available.

備註

重要

您無法將呼叫嵌入 TryStartNoGCRegion 方法,而且 EndNoGCRegion 如果執行時間目前為無 GC 區域延遲模式,則應該只呼叫方法。You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. 換句話說,您不應該在 TryStartNoGCRegion 第一次方法呼叫之後呼叫多次 (,後續的呼叫將不會成功) ,而且您不應該預期 EndNoGCRegion 只有在第一次呼叫成功時,才會成功的呼叫 TryStartNoGCRegionIn other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

TryStartNoGCRegion(Int64)

嘗試在有指定數量記憶體可用時,於執行關鍵路徑期間,禁止記憶體回收。Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available.

public:
 static bool TryStartNoGCRegion(long totalSize);
public static bool TryStartNoGCRegion (long totalSize);
[System.Security.SecurityCritical]
public static bool TryStartNoGCRegion (long totalSize);
static member TryStartNoGCRegion : int64 -> bool
[<System.Security.SecurityCritical>]
static member TryStartNoGCRegion : int64 -> bool
Public Shared Function TryStartNoGCRegion (totalSize As Long) As Boolean

參數

totalSize
Int64

在不觸發記憶體回收的情況下,要配置的記憶體數量 (以位元組為單位)。The amount of memory in bytes to allocate without triggering a garbage collection. 該值必須小於或等於暫時區段的大小。It must be less than or equal to the size of an ephemeral segment. 如需暫時區段大小的資訊,請參閱記憶體回收的基本概念一文中的<暫時層代和區段>一節。For information on the size of an ephemeral segment, see the "Ephemeral generations and segments" section in the Fundamentals of Garbage Collection article.

傳回

Boolean

如果執行階段可以認可所需的記憶體數量且記憶體回收行程可以進入無 GC 區域延遲模式,則為 true;否則為 falsetrue if the runtime was able to commit the required amount of memory and the garbage collector is able to enter no GC region latency mode; otherwise, false.

屬性

例外狀況

totalSize 超過暫時區段的大小。totalSize exceeds the ephemeral segment size.

處理序處於無 GC 區域延遲模式。The process is already in no GC region latency mode.

備註

TryStartNoGCRegion(Int64)方法會嘗試將垃圾收集行程放在無 GC 區域延遲模式中,這在應用程式執行重要的程式碼區域時,不允許垃圾收集。The TryStartNoGCRegion(Int64) method attempts to place the garbage collector in no GC region latency mode, which disallows garbage collection while an app executes a critical region of code. 如果執行時間無法一開始配置所要求的記憶體數量,垃圾收集行程就會執行完全封鎖的垃圾收集,以嘗試釋放額外的記憶體。If the runtime is unable to initially allocate the requested amount of memory, the garbage collector performs a full blocking garbage collection in an attempt to free additional memory. 如果垃圾收集行程能夠配置所需的記憶體數量(在此案例中實際上是 2 * 個位元組),垃圾收集行程就會進入無 GC 區域延遲模式 totalSize (它會嘗試為 totalSize 小型物件堆積配置位元組,並 totalSize 將位元組用於大型物件堆積) 。The garbage collector enters no GC region latency mode if it is able to allocate the required amount of memory, which in this case is actually 2 * totalSize bytes (it attempts to allocate totalSize bytes for the small object heap and totalSize bytes for the large object heap).

totalSize 必須夠大,才能處理在關鍵路徑中發生的所有記憶體配置。totalSize must be large enough to handle all memory allocations that occur in the critical path. 這包括應用程式的配置,以及執行時間代表應用程式進行的配置。This includes allocations by the app, as well as allocations that the runtime makes on the app's behalf.

重要

您無法將呼叫嵌入 TryStartNoGCRegion 方法,而且 EndNoGCRegion 如果執行時間目前為無 GC 區域延遲模式,則應該只呼叫方法。You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. 換句話說,您不應該在 TryStartNoGCRegion 第一次方法呼叫之後呼叫多次 (,後續的呼叫將不會成功) ,而且您不應該預期 EndNoGCRegion 只有在第一次呼叫成功時,才會成功的呼叫 TryStartNoGCRegionIn other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

您可以藉由呼叫方法來結束無 GC 區域延遲模式 EndNoGCRegionYou exit the no GC region latency mode by calling the EndNoGCRegion method.

另請參閱

適用於

TryStartNoGCRegion(Int64, Boolean)

嘗試在有指定數量記憶體可用時,於執行關鍵路徑期間,禁止記憶體回收,並控制在最初沒有足夠的記憶體可用時,記憶體回收行程是否執行完全封鎖記憶體回收。Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available, and controls whether the garbage collector does a full blocking garbage collection if not enough memory is initially available.

public:
 static bool TryStartNoGCRegion(long totalSize, bool disallowFullBlockingGC);
public static bool TryStartNoGCRegion (long totalSize, bool disallowFullBlockingGC);
[System.Security.SecurityCritical]
public static bool TryStartNoGCRegion (long totalSize, bool disallowFullBlockingGC);
static member TryStartNoGCRegion : int64 * bool -> bool
[<System.Security.SecurityCritical>]
static member TryStartNoGCRegion : int64 * bool -> bool
Public Shared Function TryStartNoGCRegion (totalSize As Long, disallowFullBlockingGC As Boolean) As Boolean

參數

totalSize
Int64

在不觸發記憶體回收的情況下,要配置的記憶體數量 (以位元組為單位)。The amount of memory in bytes to allocate without triggering a garbage collection. 該值必須小於或等於暫時區段的大小。It must be less than or equal to the size of an ephemeral segment. 如需暫時區段大小的資訊,請參閱記憶體回收的基本概念一文中的<暫時層代和區段>一節。For information on the size of an ephemeral segment, see the "Ephemeral generations and segments" section in the Fundamentals of Garbage Collection article.

disallowFullBlockingGC
Boolean

true 表示如果記憶體回收行程最初無法配置 totalSize 個位元組,則省略完全封鎖記憶體回收;否則為 falsetrue to omit a full blocking garbage collection if the garbage collector is initially unable to allocate totalSize bytes; otherwise, false.

傳回

Boolean

如果執行階段可以認可所需的記憶體數量且記憶體回收行程可以進入無 GC 區域延遲模式,則為 true;否則為 falsetrue if the runtime was able to commit the required amount of memory and the garbage collector is able to enter no GC region latency mode; otherwise, false.

屬性

例外狀況

totalSize 超過暫時區段的大小。totalSize exceeds the ephemeral segment size.

處理序處於無 GC 區域延遲模式。The process is already in no GC region latency mode.

備註

TryStartNoGCRegion(Int64, Boolean)方法會嘗試將垃圾收集行程放在無 GC 區域延遲模式中,這在應用程式執行重要的程式碼區域時,不允許垃圾收集。The TryStartNoGCRegion(Int64, Boolean) method attempts to place the garbage collector in no GC region latency mode, which disallows garbage collection while an app executes a critical region of code. 如果執行時間無法一開始配置要求的記憶體數量 disallowFullBlockingGC ,而且引數是 false ,垃圾收集行程會在嘗試釋放額外的記憶體時執行完全封鎖垃圾收集; 否則,配置將會失敗,而且方法會傳回 falseIf the runtime is unable to initially allocate the requested amount of memory and the disallowFullBlockingGC argument is false, the garbage collector performs a full blocking garbage collection in an attempt to free additional memory; otherwise, the allocation fails, and the method returns false. 如果垃圾收集行程能夠配置所需的記憶體數量(在此案例中,實際上是 2 * totalSize (它會嘗試為 totalSize 小型物件堆積和 totalSize 大型物件堆積) 配置,則會進入無 GC 區域延遲模式。The garbage collector enters no GC region latency mode if it is able to allocate the required amount of memory, which in this case is actually 2 * totalSize (it attempts to allocate totalSize for the small object heap and totalSize for the large object heap).

totalSize 必須夠大,才能處理在關鍵路徑中發生的所有記憶體配置。totalSize must be large enough to handle all memory allocations that occur in the critical path. 這包括應用程式的配置,以及執行時間代表應用程式進行的配置。This includes allocations by the app, as well as allocations that the runtime makes on the app's behalf.

將設定 disallowFullBlockingGCtrue ,以防止一開始可用的記憶體不足時封鎖垃圾收集,最適合用於負載平衡案例:一個系統可以呼叫這個方法,並將本身回報為準備好接受要求(如果傳回 true ),並讓負載平衡器將要求重新導向至其他系統(如果傳回) falseSetting disallowFullBlockingGC to true to prevent a full blocking garbage collection if not enough memory is initially available is most useful in load balancing scenarios: one system can call this method and report itself as ready to accept requests if it returns true, and have the load balancer redirect requests to other systems if it returns false. 然後,它可以在未藉由呼叫方法來處理要求時,進行完全封鎖的垃圾收集 Collect(Int32, GCCollectionMode, Boolean, Boolean)It can then do a full blocking garbage collection when it's not handling requests by calling the Collect(Int32, GCCollectionMode, Boolean, Boolean) method.

重要

您無法將呼叫嵌入 TryStartNoGCRegion 方法,而且 EndNoGCRegion 如果執行時間目前為無 GC 區域延遲模式,則應該只呼叫方法。You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. 換句話說,您不應該在 TryStartNoGCRegion 第一次方法呼叫之後呼叫多次 (,後續的呼叫將不會成功) ,而且您不應該預期 EndNoGCRegion 只有在第一次呼叫成功時,才會成功的呼叫 TryStartNoGCRegionIn other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

您可以藉由呼叫方法來結束無 GC 區域延遲模式 EndNoGCRegionYou exit the no GC region latency mode by calling the EndNoGCRegion method.

另請參閱

適用於

TryStartNoGCRegion(Int64, Int64)

嘗試在大型物件堆積與小型物件堆積有指定數量記憶體可用時,於執行關鍵路徑期間,禁止記憶體回收。Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available for the large object heap and the small object heap.

public:
 static bool TryStartNoGCRegion(long totalSize, long lohSize);
public static bool TryStartNoGCRegion (long totalSize, long lohSize);
[System.Security.SecurityCritical]
public static bool TryStartNoGCRegion (long totalSize, long lohSize);
static member TryStartNoGCRegion : int64 * int64 -> bool
[<System.Security.SecurityCritical>]
static member TryStartNoGCRegion : int64 * int64 -> bool
Public Shared Function TryStartNoGCRegion (totalSize As Long, lohSize As Long) As Boolean

參數

totalSize
Int64

在不觸發記憶體回收的情況下,要配置的記憶體數量 (以位元組為單位)。The amount of memory in bytes to allocate without triggering a garbage collection. totalSize -lohSize 必須小於或等於暫時區段的大小。totalSize -lohSize must be less than or equal to the size of an ephemeral segment. 如需暫時區段大小的資訊,請參閱記憶體回收的基本概念一文中的<暫時層代和區段>一節。For information on the size of an ephemeral segment, see the "Ephemeral generations and segments" section in the Fundamentals of Garbage Collection article.

lohSize
Int64

totalSize 中要用於大型物件堆積 (LOH) 配置的位元組數目。The number of bytes in totalSize to use for large object heap (LOH) allocations.

傳回

Boolean

如果執行階段可以認可所需的記憶體數量且記憶體回收行程可以進入無 GC 區域延遲模式,則為 true;否則為 falsetrue if the runtime was able to commit the required amount of memory and the garbage collector is able to enter no GC region latency mode; otherwise, false.

屬性

例外狀況

totalSize - lohSize 超過暫時區段大小。totalSize - lohSize exceeds the ephemeral segment size.

處理序處於無 GC 區域延遲模式。The process is already in no GC region latency mode.

備註

TryStartNoGCRegion(Int64, Int64)方法會嘗試將垃圾收集行程放在無 GC 區域延遲模式中,這在應用程式執行重要的程式碼區域時,不允許垃圾收集。The TryStartNoGCRegion(Int64, Int64) method attempts to place the garbage collector in no GC region latency mode, which disallows garbage collection while an app executes a critical region of code. 如果執行時間無法一開始配置所要求的記憶體數量,垃圾收集行程就會執行完全封鎖的垃圾收集,以嘗試釋放額外的記憶體。If the runtime is unable to initially allocate the requested amount of memory, the garbage collector performs a full blocking garbage collection in an attempt to free additional memory. 如果可以為 lohSize LOH 和 totalSize - lohSize 小型物件堆積配置 (SOH) ,則垃圾收集行程不會進入 GC 區域延遲模式。The garbage collector enters no GC region latency mode if it is able to allocate lohSize for the LOH and totalSize - lohSize for the small object heap (SOH).

lohSize必須夠大,才能處理 LOH 的關鍵路徑中發生的所有記憶體配置,且 totalSize - lohSize 必須夠大,才能處理 SOH 之關鍵路徑中發生的所有記憶體配置。lohSize must be large enough to handle all memory allocations that occur in the critical path for the LOH, and totalSize - lohSize must be large enough to handle all memory allocations that occur in the critical path for the SOH. 這包括應用程式的配置,以及執行時間代表應用程式進行的配置。This includes allocations by the app, as well as allocations that the runtime makes on the app's behalf.

重要

您無法將呼叫嵌入 TryStartNoGCRegion 方法,而且 EndNoGCRegion 如果執行時間目前為無 GC 區域延遲模式,則應該只呼叫方法。You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. 換句話說,您不應該在 TryStartNoGCRegion 第一次方法呼叫之後呼叫多次 (,後續的呼叫將不會成功) ,而且您不應該預期 EndNoGCRegion 只有在第一次呼叫成功時,才會成功的呼叫 TryStartNoGCRegionIn other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

您可以藉由呼叫方法來結束無 GC 區域延遲模式 EndNoGCRegionYou exit the no GC region latency mode by calling the EndNoGCRegion method.

另請參閱

適用於

TryStartNoGCRegion(Int64, Int64, Boolean)

嘗試在大型物件堆積與小型物件堆積有指定數量記憶體可用時,於執行關鍵路徑期間,禁止記憶體回收,並控制在最初沒有足夠的記憶體可用時,記憶體回收行程是否執行完全封鎖記憶體回收。Attempts to disallow garbage collection during the execution of a critical path if a specified amount of memory is available for the large object heap and the small object heap, and controls whether the garbage collector does a full blocking garbage collection if not enough memory is initially available.

public:
 static bool TryStartNoGCRegion(long totalSize, long lohSize, bool disallowFullBlockingGC);
public static bool TryStartNoGCRegion (long totalSize, long lohSize, bool disallowFullBlockingGC);
[System.Security.SecurityCritical]
public static bool TryStartNoGCRegion (long totalSize, long lohSize, bool disallowFullBlockingGC);
static member TryStartNoGCRegion : int64 * int64 * bool -> bool
[<System.Security.SecurityCritical>]
static member TryStartNoGCRegion : int64 * int64 * bool -> bool
Public Shared Function TryStartNoGCRegion (totalSize As Long, lohSize As Long, disallowFullBlockingGC As Boolean) As Boolean

參數

totalSize
Int64

在不觸發記憶體回收的情況下,要配置的記憶體數量 (以位元組為單位)。The amount of memory in bytes to allocate without triggering a garbage collection. totalSize -lohSize 必須小於或等於暫時區段的大小。totalSize -lohSize must be less than or equal to the size of an ephemeral segment. 如需暫時區段大小的資訊,請參閱記憶體回收的基本概念一文中的<暫時層代和區段>一節。For information on the size of an ephemeral segment, see the "Ephemeral generations and segments" section in the Fundamentals of Garbage Collection article.

lohSize
Int64

totalSize 中要用於大型物件堆積 (LOH) 配置的位元組數目。The number of bytes in totalSize to use for large object heap (LOH) allocations.

disallowFullBlockingGC
Boolean

true 表示如果記憶體回收行程最初無法在小型物件堆積 (SOH) 及 LOH 上配置指定的記憶體,則省略完全封鎖記憶體回收;否則為 falsetrue to omit a full blocking garbage collection if the garbage collector is initially unable to allocate the specified memory on the small object heap (SOH) and LOH; otherwise, false.

傳回

Boolean

如果執行階段可以認可所需的記憶體數量且記憶體回收行程可以進入無 GC 區域延遲模式,則為 true;否則為 falsetrue if the runtime was able to commit the required amount of memory and the garbage collector is able to enter no GC region latency mode; otherwise, false.

屬性

例外狀況

totalSize - lohSize 超過暫時區段大小。totalSize - lohSize exceeds the ephemeral segment size.

處理序處於無 GC 區域延遲模式。The process is already in no GC region latency mode.

備註

TryStartNoGCRegion(Int64, Int64, Boolean)方法會嘗試將垃圾收集行程放在無 GC 區域延遲模式中,這在應用程式執行重要的程式碼區域時,不允許垃圾收集。The TryStartNoGCRegion(Int64, Int64, Boolean) method attempts to place the garbage collector in no GC region latency mode, which disallows garbage collection while an app executes a critical region of code. 如果執行時間無法一開始配置要求的記憶體數量 disallowFullBlockingGC ,而且引數是 false ,垃圾收集行程會在嘗試釋放額外的記憶體時執行完全封鎖垃圾收集; 否則,配置將會失敗,而且方法會傳回 falseIf the runtime is unable to initially allocate the requested amount of memory and the disallowFullBlockingGC argument is false, the garbage collector performs a full blocking garbage collection in an attempt to free additional memory; otherwise, the allocation fails, and the method returns false. 如果可以為 lohSize LOH 和 totalSize - lohSize 小型物件堆積配置 (SOH) ,則垃圾收集行程不會進入 GC 區域延遲模式。The garbage collector enters no GC region latency mode if it is able to allocate lohSize for the LOH and totalSize - lohSize for the small object heap (SOH).

lohSize必須夠大,才能處理 LOH 的關鍵路徑中發生的所有記憶體配置,且 totalSize - lohSize 必須夠大,才能處理 SOH 之關鍵路徑中發生的所有記憶體配置。lohSize must be large enough to handle all memory allocations that occur in the critical path for the LOH, and totalSize - lohSize must be large enough to handle all memory allocations that occur in the critical path for the SOH. 這包括應用程式的配置,以及執行時間代表應用程式進行的配置。This includes allocations by the app, as well as allocations that the runtime makes on the app's behalf.

將設定 disallowFullBlockingGCtrue ,以防止一開始可用的記憶體不足時封鎖垃圾收集,最適合用於負載平衡案例:一個系統可以呼叫這個方法,並將本身回報為準備好接受要求(如果傳回 true ),並讓負載平衡器將要求重新導向至其他系統(如果傳回) falseSetting disallowFullBlockingGC to true to prevent a full blocking garbage collection if not enough memory is initially available is most useful in load balancing scenarios: one system can call this method and report itself as ready to accept requests if it returns true, and have the load balancer redirect requests to other systems if it returns false. 然後,它可以在未藉由呼叫方法來處理要求時,進行完全封鎖的垃圾收集 Collect(Int32, GCCollectionMode, Boolean, Boolean)It can then do a full blocking garbage collection when it's not handling requests by calling the Collect(Int32, GCCollectionMode, Boolean, Boolean) method.

重要

您無法將呼叫嵌入 TryStartNoGCRegion 方法,而且 EndNoGCRegion 如果執行時間目前為無 GC 區域延遲模式,則應該只呼叫方法。You cannot nest calls to the TryStartNoGCRegion method, and you should only call the EndNoGCRegion method if the runtime is currently in no GC region latency mode. 換句話說,您不應該在 TryStartNoGCRegion 第一次方法呼叫之後呼叫多次 (,後續的呼叫將不會成功) ,而且您不應該預期 EndNoGCRegion 只有在第一次呼叫成功時,才會成功的呼叫 TryStartNoGCRegionIn other words, you should not call TryStartNoGCRegion multiple times (after the first method call, subsequent calls will not succeed), and you should not expect calls to EndNoGCRegion to succeed just because the first call to TryStartNoGCRegion succeeded.

您可以藉由呼叫方法來結束無 GC 區域延遲模式 EndNoGCRegionYou exit the no GC region latency mode by calling the EndNoGCRegion method.

另請參閱

適用於