ArrayCopy on same array: data corruption?

 

 Hi, I read that using ArrayCopy on the same array could cause data corruption when the initial source index is lower than the target index, due to the left-to-right copy.

I tried, but no data corruption was detected. Can I be sure this won't happen under any circumstances?

Here a simple script:

   int arr1[6] = {0,1,2,3,4,5};
   ArrayCopy(arr1, arr1, 1, 0, WHOLE_ARRAY);
   ArrayPrint(arr1);

   //shift to left
   int arr2[6] = {0,1,2,3,4,5};
   ArrayCopy(arr2, arr2, 0, 1, WHOLE_ARRAY);
   ArrayPrint(arr2);


Thanks for help.

 
antony23:

 Hi, I read that using ArrayCopy on the same array could cause data corruption when the initial source index is lower than the target index, due to the left-to-right copy.

I tried, but no data corruption was detected. Can I be sure this won't happen under any circumstances?

Here a simple script:


Thanks for help.

Where did you read that ?
 

Here in the documentation, we are warned that "It is permitted to copy elements from an array to itself. But if the target and source areas overlap, you need to keep in mind that the iteration is done from left to right". 

In this forum post same conclusion, and also gemini google answer statament same thing.

Manuale MQL5: Copying and editing arrays / Common APIs
Manuale MQL5: Copying and editing arrays / Common APIs
  • www.mql5.com
In this section, we'll learn how to use built-in functions to insert and remove array elements, change their order, and copy entire arrays. bool...
 
antony23 #:

Here in the documentation, we are warned that "It is permitted to copy elements from an array to itself. But if the target and source areas overlap, you need to keep in mind that the iteration is done from left to right". 

It's not stated in this link to the book that there could be a data corruption. Just that the iteration is done from left to right.

In this forum post same conclusion, and also gemini google answer statament same thing.

This forum post gives wrong information (possibly something changed since 2023).

In summary, there is no data corruption using ArrayCopy in MQL5.

 
So why we should keep in mind that iteration is done left to right? 
Maybe it would make difference if array is set asSeries?