Passing an array to a function: any way to make it type-independent? - page 3

 
WHRoeder: No But. My ResizeBuffer has been working for 4 years. You have the asSeries backwards.

I'm sure your code and RaptorUK methods work perfectly on Current mt4. What I was looking to accomplish (again) was comparing Overloading vs Switch within the Beta_Mt4.

I ran into allot of in-consistency's with Current_Mt4 || Beta_Mt4 || Current_Mt5. Was just trying to let people know there's a difference.

How do you feel about the Beta_ implementing the same codes differently compared to the last 4-years?

I'm sure I've probably gotten the asSeries backwards .. lol .. my concern is that its being implemented differently.

Do you feel your 4-Year old code would continue working with-in the New_Mt4?

Example: The same codes ... except the un-signed int below ....

1st>Current_Mt4:

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void start(){
    int iTenMillion=10000000;
    int iStaticArray[5]={0,1,2,3,4};
    int iBegin=GetTickCount();
    
    for(int i=0; i<iTenMillion; i++)
        ArrayPrependSpeedTestY(iStaticArray,i);
    
    int iFinish=GetTickCount()-iBegin;
    Print("Number Of MilliSeconds To Complete =",iFinish);
    PrintIntegerArrayContents(iStaticArray,5);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void ArrayPrependSpeedTestY(int& vector[], int val){
    ArraySetAsSeries( vector, true );
    ArrayResize( vector, ArraySize(vector)+1 );
    ArraySetAsSeries( vector, false );
    ArrayResize( vector, ArraySize(vector)-1 );
    vector[0] = val;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void PrintIntegerArrayContents(int& iDynamicArray[], int iSampleSize){
    int iCounter=0;
    for(int i=ArraySize(iDynamicArray)-1; i>=0; i--){
        Print("i=",i,"___Value=",iDynamicArray[i]); iCounter++;
        if(iCounter>=iSampleSize) break;
    }
    Print("_________________________________");
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Current Mt4 Results:

11:48:30 TestingF EURUSD,M1: loaded successfully
11:48:36 TestingF EURUSD,M1: Number Of MilliSeconds To Complete =6209
11:48:36 TestingF EURUSD,M1: i=4___Value=9999995
11:48:36 TestingF EURUSD,M1: i=3___Value=9999996
11:48:36 TestingF EURUSD,M1: i=2___Value=9999997
11:48:36 TestingF EURUSD,M1: i=1___Value=9999998
11:48:36 TestingF EURUSD,M1: i=0___Value=9999999
11:48:36 TestingF EURUSD,M1: _________________________________
11:48:36 TestingF EURUSD,M1: uninit reason 0
11:48:36 TestingF EURUSD,M1: removed

Now the Beta_Mt4:

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void start(){
    int iTenMillion=10000000;
    int iStaticArray[5]={0,1,2,3,4};
    uint iBegin=GetTickCount();
    
    for(int i=0; i<iTenMillion; i++)
        ArrayPrependSpeedTestY(iStaticArray,i);
    
    uint iFinish=GetTickCount()-iBegin;
    Print("Number Of MilliSeconds To Complete =",iFinish);
    PrintIntegerArrayContents(iStaticArray,5);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void ArrayPrependSpeedTestY(int& vector[], int val){
    ArraySetAsSeries( vector, true );
    ArrayResize( vector, ArraySize(vector)+1 );
    ArraySetAsSeries( vector, false );
    ArrayResize( vector, ArraySize(vector)-1 );
    vector[0] = val;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void PrintIntegerArrayContents(int& iDynamicArray[], int iSampleSize){
    int iCounter=0;
    for(int i=ArraySize(iDynamicArray)-1; i>=0; i--){
        Print("i=",i,"___Value=",iDynamicArray[i]); iCounter++;
        if(iCounter>=iSampleSize) break;
    }
    Print("_________________________________");
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Beta Results:

11:51:40 Script TestingF EURUSD,M1: loaded successfully
11:51:40 TestingF EURUSD,M1: Number Of MilliSeconds To Complete =718
11:51:40 TestingF EURUSD,M1: i=4___Value=3
11:51:40 TestingF EURUSD,M1: i=3___Value=2
11:51:40 TestingF EURUSD,M1: i=2___Value=1
11:51:40 TestingF EURUSD,M1: i=1___Value=0
11:51:40 TestingF EURUSD,M1: i=0___Value=9999999
11:51:40 TestingF EURUSD,M1: _________________________________
11:51:40 Script TestingF EURUSD,M1: removed

So where am I going wrong?

 
2cent:
...and perferably use a buffer size of a power of 2:

You need a power of 2 buffer.

With this trick:

 i & cbuf_size_minus_1

you are forcing an array index to a fixed bit size, the array can be longer but cannot be indexed beyond the index

the 1 digits define the lenght of it, you cannot have 0 digits inside of it or you will have not indexable "holes" of 2^X size (where X is the position of the 0)

so the sizes (filters) available are 0x01 0x03 0x07 0x0F 0x1F 0x3F 0x7F 0xFF and so on

correct me if i am wrong :)

Reason: