The function sets a new size for the first dimension
[out] Array for changing sizes.
[in] New size for the first dimension.
[in] Distributed size to get reserve.
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.
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:
In this case the memory will be reallocated twice, first before entering the 2000-element 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.