Class TCastleFastList

Unit

Declaration

type generic TCastleFastList<T> = class(TObject)

Description

Simple fast list. Exposes most common operations, like addition and reading.

Can be specialized with any type (simple types like integers, or records, class instances...) that does not need automatic memory management. So don't use with e.g. AnsiStrings or COM interfaces or records with them (we would not initialize/release such memory properly).

Does not have any "ownership" (like in TObjectList that can "own" children) or notification mechanism (that would call a method / callback every time something is added / removed). This avoids operations that would force things like "clear" to perform one-by-one iteration over items (like notification of removals or dropping reference counts).

Manages memory to optimize speed, not conserve memory: operations only allocate memory, until you do ReleaseMemory (or free this instance, of course). Aside from this, we only grow, even when you call Clear.

Hierarchy

  • TObject
  • TCastleFastList

Overview

Nested Types

Public PtrT = ˆT;

Methods

Public destructor Destroy; override;
Public procedure Add(const Item: T);
Public procedure Clear;
Public procedure ReleaseMemory;
Public procedure AllocateAtLeast(const MinimumCapacity: Integer);
Public procedure Assign(const Source: TCastleFastList );
Public procedure AddRange(const Source: TCastleFastList );

Properties

Public property Count: Integer read FCount;
Public property Items[const Index: Integer]: T read GetItems write SetItems;
Public property L: PtrT read FItems;

Description

Nested Types

Public PtrT = ˆT;

Pointer to the list contents.

Methods

Public destructor Destroy; override;

This item has no description.

Public procedure Add(const Item: T);

Add new item.

Public procedure Clear;

Clearing is equivalent to setting Count := 0. Does not deallocate memory (to keep it for future reuse), call ReleaseMemory if you want to do that.

Public procedure ReleaseMemory;

This item has no description.

Public procedure AllocateAtLeast(const MinimumCapacity: Integer);

This item has no description.

Public procedure Assign(const Source: TCastleFastList );

This item has no description.

Public procedure AddRange(const Source: TCastleFastList );

This item has no description.

Properties

Public property Count: Integer read FCount;

How many items are in the list.

Public property Items[const Index: Integer]: T read GetItems write SetItems;

Get or set items in the list.

Public property L: PtrT read FItems;

Access the list contents through a pointer, to get or set them efficiently.

Use this to directly access a list value, like this:

MyIntList.L[I] := 123;
// Equivalent but less efficient to syntax without L:
// MyIntList[I] := 123;

MyRecordList.L[I].MyField := 123;
// Never use syntax without L (could modify temporary value):
// MyRecordList[I].MyField := 123; //< never do this!

The above examples of L work only in FPC ObjFpc mode or in Delphi with pointermath "on" (see https://docwiki.embarcadero.com/RADStudio/Sydney/en/Pointer_Math_(Delphi) ). These are CGE default settings when being compiled with FPC or Delphi, so you can depend on them at least in CGE implementation. Note that Delphi code using this doesn't need to be compiled with pointermath "on", it is enough that this unit is compiled with pointermath "on" and then one can use math on PtrT.

This is in particular useful if you have a list of records and you would like to set their fields.


Generated by PasDoc 0.16.0-snapshot.