Class
TVec
SliceItc allows you to slice the memory allocated by the calling vector in to smaller pieces and returns array pointers to those pieces. Many times dynamic allocation of arrays is required explicitely and consequtive calls of GetMem/FreeMem can get fairly expensive. Use this method when allocating memory for small arrays. If the sum of sizes of all arrays: n1+n2+n3+n4 does not exceed VecCacheElements, no memory allocation is performed at all, because the TVec object already has enough memory preallocated. If however more memory is required then a total of up to four call's to GetMem/FreeMem are reduced to only one.
You should never free memory obtained from the SliceIt method. This memory is already handled within the TVec object. The performance gain of the SliceIt method over the call to GetMem and then FreeMem is about 10x. This gain gives TVec arithmetics enough boost, to compensate for losses in object wrapping's and in ConditionCheck when handling short vectors. It allows a more clean and safe code, because the work array's need not be passed to the procedures. They can be "allocated" within procedures.
.NET specificsThe function returns IntPtr type pointers to unmanaged memory.
| See Also |
|---|
| SliceIt |
| ActualLength |
| Length |
| Complex |
var a: TVec; p1,p2,p3,p4: PPCplx; begin CreateIt(a); try a.SliceIt(2,2,2,2,p1,p2,p3,p4); p1[0] := 1; p1[1] := 3; p2[0] := 2; p2[1] := 4; p3[0] := 5; p3[1] := 6; p4[0] := 7; p4[1] := 8; // a becomes [1,3, 2,4 ,5,6, 7,8,......], // but the meaning of SliceIt is to pass array pointers // to procedures where required, thus avoiding the need to call GetMem: DoMyThing(1,2,p1,p2); finally FreeIt(a); // memory associated with array pointers is freed end; end;
| Copyright 2008 Dew Research |