LazListClasses unit
Provides list classes implemented using generics.
lazlistclasses.pas contains list classes implemented using
generics. The lists are provided as "object" and "class" versions. Each list
can be specialized to hold either items of a given type (specialized to type
at compile-time) or untyped data with the size specified as a run-time
argument to the constructor.
Note about "object" variants:
- Object instanes are stored on the stack, and as such the memory of the object itself.
- An object instance is freed when the variable goes out of scope. The objects do however allocate additional memory on the heap. So it is necessary to call Destroy.
- It is also necessary to call Create. (Unless you can guarantee that the memory of the object has been zero filled).
- To use the lists with managed types, the correct MemInit must be configured.
TGenLazShiftList
This list is designed for shift/unshift/pop/push operations. The first list element is not forced to the start of the allocated memory. Instead it allows a gap (some of the over-allocated memory / List.Capacity) in front of the first element. Therefore elements can be added/removed at either the begin or end of the list, without any need to move the other elements in the list.
TGenLazRoundList
The first element of the list can be anywhere within the allocated memory (capacity). If the elements of the list reach the end of the memory, the list will wrap around and continues in the available memory at the start of the allocation. This list can be used for a first-in, first-out queue. If the list does never exceed the size set by its capacity, then elements can be pushed/shifted from/to the list without any need to reallocate or move entries to new locations.
TGenLazPagedList
This list organize its data into pages of fixed size. If the list grows or shrinks it can allocate extra pages or free existing pages. It does not need to reallocate its entire memory. This means that growing needs less extra memory than conventional lists. The page size is specified in the call to the constructor. The size has to be a power of 2. The constructor takes the exponent as argument. (e.g. an argument of "10" will give a size of 1024).
The list also acts like a TLazShiftBufferList.
Variants of the above lists
- VarSize
- Lists take an "ItemSize" in the constructor. Elements are accessed via ItemPointer (which may be a plain pointer or typed pointer).
- FixedSize
- Lists are compiled for a fixed itemsize (usually "SizeOf(type)".
- FixedType
- In addition to FixedSize there is an "Items" property and "IndexOf" can take an item (instead of a pointer). For this, items need to have a compare operator.
The samples below show the available variants of the above list. The constructor for each sample is included.
Helpers for specializing the variants
Either of the following can be specified to generics that take a "TSizeT"
type generic TLazListAspectItemSize<T> = object
Used for specializing lists with a fixed item size. The size will be: sizeof(T).
type TLazListAspectVarItemSize = object
Used for specializing a list with a configurable item size. The size must be set in the constructor and can not be changed after this. When using this, you need to add a constructor setting:
fItemSize.ItemSize := ASize; // "ASize" is your size
lazlistclasses.pas is part of the
LazUtils package.
Classes and records
Types
TLazListAspectCapacityCallback | type | |
TLazStorageMemGrowProc | procedure type | |
TLazStorageMemShrinkProc | procedure type |
Uses
An experiment, built from development snapshots. Not the official Free Pascal or Lazarus documentation.
