Download MetaTrader 5
To add comments, please log in or register
Have you just installed MetaTrader 5? Learn it in details!
gatornuke
353
gatornuke 2010.09.14 21:49 

If i resize an array which already contains data, will this erase all data or just add an extra slot?

i.e., is

ArrayResize({1,1,1},4) = {1,1,1,NULL}?

Nikolay Panev
1060
Nikolay Panev 2010.09.14 21:55  
gatornuke:

If i resize an array which already contains data, will this erase all data or just add an extra slot?

i.e., is

ArrayResize({1,1,1},4) = {1,1,1,NULL}?

It won't erase the existing data.
gatornuke
353
gatornuke 2010.09.14 23:37  

Ok, Good. Thanks.

Phillip
800
Phillip 2010.09.15 07:02  

likewise if you resize an existing array to become a smaller array it merely truncates (deletes) the data that existed in the elements that will no longer exist in the new array

ArrayResize({1,1,1},2)={1,1}

gatornuke
353
gatornuke 2010.09.15 17:09  

i see...

whroeder1
13641
whroeder1 2010.09.15 18:20  
You can get {3,2,1,null} or {null,1,2,3} Article: Effective usage of Arrays in MQL
    ArraySetAsSeries(mem, true);        // Shift values m[2]=m[1]; m[1]=m[0]
    int firstBar=ArrayResize(mem, size+1)-1;    if (firstBar < 0){      Alert(
        "ArrayResize failed: ",GetLastError());                         return;}
    ArraySetAsSeries(mem, false);     
 mem[0]=...
...
    ArrayResize(mem, maxBar+1); // Drop firstBar..(maxBar+1)
john
213
john 2013.12.29 21:51  
WHRoeder:
You can get {3,2,1,null} or {null,1,2,3} Article: Effective usage of Arrays in MQL

With ArrayResize() an incremental element/index is added on a recurring basis, it would have to (I presume) select memory from non contiguous locations each time wouldn't it? A 500,000 element array could then have fragmented addresses between virutually all of it's elements, and leads me to a question. Initializing a large Array size would (presumably) select memory with contiguous addresses, so..


Is one way better than the other as far a processing time, when calculations are made from the arrays.

Contiguous addresses versus non-contiguous addresses? Is one slower and less efficient than the other, in performing calculations?

Thanks

whroeder1
13641
whroeder1 2013.12.30 02:51  

Most implementations will allocate additional space so subsequent allocations will be simple (amortizing the reallocation costs.) When actual memory needs to be allocated usually the data will be copied to the new allocated location and the old released, thus keeping the array contiguous.

Which is better depends on the application. Which mt4 uses is anybodies guess. I believe (based only on my hunch and the measured fact that array reference takes a measured 10x vs variable access,) that mt4 uses a Deque (STL) not a contiguous array.

john
213
john 2013.12.30 03:55  

Okay Thanks. So far I have 6. Each is pre-set for 500k 1 dim index size.

I see many others that use ArrayResize to "grow" an array. I thought that could be an overuse of ArraySize intention, and that "growing" an array (my term) was actually not an array, but a Vector?

I wanted to use it too, but didn't know if it should be done as the primary method of sizing. Especially if it would burden my calculation times. Sounds like I could try ArrayResize, and incrementally scale them.

Most of my calculations will be done inside Deinit() for data profiling, so I don't care how slow they run. But some, like correlation coefficient will be run live on every bar or two .

thanks


whroeder1
13641
whroeder1 2015.05.30 17:11  
New in Build 600+ Using the third argument to ArrayResize - MQL4 Documentation allows preallocation of memory.
/
To add comments, please log in or register