Queue.TrimToSize 方法

定义

将容量设置为 Queue 中元素的实际数目。Sets the capacity to the actual number of elements in the Queue.

public:
 virtual void TrimToSize();
public virtual void TrimToSize ();
abstract member TrimToSize : unit -> unit
override this.TrimToSize : unit -> unit
Public Overridable Sub TrimToSize ()

例外

Queue 为只读。The Queue is read-only.

注解

如果不向队列中添加新的元素,则可以使用此方法最大程度地减少队列的内存开销。This method can be used to minimize a queue's memory overhead if no new elements will be added to the queue.

若要将重置 Queue 为其初始状态,请 Clear 在调用之前调用方法 TrimToSizeTo reset a Queue to its initial state, call the Clear method before calling TrimToSize. 修整空会将的 Queue 容量设置 Queue 为默认容量。Trimming an empty Queue sets the capacity of the Queue to the default capacity.

此方法是一个 O(n) 操作,其中 nCountThis method is an O(n) operation, where n is Count.

适用于

另请参阅