- ArrayBsearch
- ArrayCopy
- ArrayCompare
- ArrayFree
- ArrayGetAsSeries
- ArrayInitialize
- ArrayFill
- ArrayIsDynamic
- ArrayIsSeries
- ArrayMaximum
- ArrayMinimum
- ArrayPrint
- ArrayRange
- ArrayResize
- ArrayInsert
- ArrayRemove
- ArrayReverse
- ArraySetAsSeries
- ArraySize
- ArraySort
- ArraySwap
- ArrayToFP16
- ArrayToFP8
- ArrayFromFP16
- ArrayFromFP8
ArrayResize
The function sets a new size for the first dimension
int ArrayResize(
|
Parameters
array[]
[out] Array for changing sizes.
new_size
[in] New size for the first dimension.
reserve_size=0
[in] Distributed size to get reserve.
Return Value
If executed successfully, it returns count of all elements contained in the array after resizing, otherwise, returns -1, and array is not resized.
If ArrayResize() is applied to a static array, a timeseries or an indicator buffer, the array size remains the same – these arrays will not be reallocated. In this case, if new_size<=ArraySize(array), the function will only return new_size; otherwise a value of -1 will be returned.
Note
The function can be applied only to dynamic arrays. It should be noted that you cannot change the size of dynamic arrays assigned as indicator buffers by the SetIndexBuffer() function. For indicator buffers, all operations of resizing are performed by the runtime subsystem of the terminal.
Total amount of elements in the array cannot exceed 2147483647.
With the frequent memory allocation, it is recommended to use a third parameter that sets a reserve to reduce the number of physical memory allocations. All the subsequent calls of ArrayResize do not lead to physical reallocation of memory, but only change the size of the first array dimension within the reserved memory. It should be remembered that the third parameter will be used only during physical memory allocation. For example:
ArrayResize(arr,1000,1000);
|
In this case the memory will be reallocated twice, first before entering the 3000 iterations loop (the array size will be set to 1000), and the second time with i equal to 2000. If we skip the third parameter, there will be 2000 physical reallocations of memory, which will slow down the program.
Example:
//+------------------------------------------------------------------+
|
See also