Home  |  Delphi .net Home  |  System.Collections.Queue  |  TrimToSize Method
TrimToSize  
Method  
Removes unused space in the current Queue
Queue Class
System.Collections NameSpace
CF1.  Procedure TrimToSize ( ) ;
CF : Methods with this mark are Compact Framework Compatible
Description
The capacity ofthe Queue is reduced to just hold the current Count of elements.
Notes
There is no Capacity property that can be used to inspect or set the Queue capacity. (Other collections, such as ArrayList do have).
Microsoft MSDN Links
System.Collections
System.Collections.Queue
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

uses
  System.Collections;

var
  MyQueue    : System.Collections.Queue;

begin
  // Create our queue with default capacity of 16 items
  MyQueue := Queue.Create;

  // Fill it
  MyQueue.Enqueue('First');
  MyQueue.Enqueue('Second');
  MyQueue.Enqueue('Third');

  Console.WriteLine('MyQueue Count = {0}', MyQueue.Count.ToString);
  Console.WriteLine;

  // Trim to size
  MyQueue.TrimToSize;

  // The count is not affected
  // There is no 'Capacity' property that can be inspected
  Console.WriteLine('MyQueue Count = {0}', MyQueue.Count.ToString);

  Console.Readline;
end.
Show full unit code
  MyQueue count = 3
  
  MyQueue count = 3
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author