Overload List
| # | Signature | Description |
|---|---|---|
| 1 | procedure SetSubRange; | Sets the subarray size to full size. |
| └ indexed: procedure SetSubRange(Index: Integer; Len: Integer); | ||
| 2 | procedure SetSubRange(const Src: TMtxVec); | Defines the calling vector to have the view of the same memory as Src. |
| └ indexed: procedure SetSubRange(const Src: TMtxVec; Index: Integer; Len: Integer); |
Overload 1: procedure SetSubRange;
Sets the subarray size to full size.
Result: stored in self (calling object)
This method is the same as the Vector.SetFullRange method.
Indexed: procedure SetSubRange(Index: Integer; Len: Integer);
Defines a sub vector/matrix.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Index | Integer | start index |
| 2 | Len | Integer | element count |
Result: stored in self (calling object)
The method will define a subarray starting at Index and ending at Index+Len-1. No copying will occur, only pointers will be shifted.
All values of the original Vector will be preserved. An exception will be raised if an attempt is made to change the size of calling object.
A sub-vector/matrix is vector/matrix which does not neccessarily have its own memory allocated. Instead it adopts the memory of the source object and all operations done on the either of the objects affect the same elements. The use of subvectors/submatrices increases CPU cache reuse, lower's memory requirements, increases application performance and improves code readability.
Note
To again obtain a view of the full vector/matrix, see Vector.SetFullRange
Overload 2: procedure SetSubRange(const Src: TMtxVec);
Defines the calling vector to have the view of the same memory as Src.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Src | TMtxVec |
Result: stored in self (calling object)
Src vector's Length property may not change while any other object has it's own view of it.
a.SetSubRange(b,..);
This SetSubRange method is to be handled with greater care. Namely:
- b can be freed before "a" and accessing "a" gives AV.
- a can be further subranged with c and same problem occurs when b is freed before c.
- If you resize b, all objects which have subranged b are no longer pointing to valid memory.
- b can Subrange other objects. Similar problem as when changing the size of b. Again all objects which have subranged b are not longer pointing to valid memory.
All this can lead to hard to find bugs.
Indexed: procedure SetSubRange(const Src: TMtxVec; Index: Integer; Len: Integer);
Define a subvector of the Src vector starting at Index and ending at Index+Len-1.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | Src | TMtxVec | |
| 2 | Index | Integer | start index |
| 3 | Len | Integer | element count |
Result: stored in self (calling object)