Download MetaTrader 5

c++ vector like array

To add comments, please log in or register
Mohsen Khashei
621
Mohsen Khashei 2014.07.25 13:47 

Hi I'm working on a mql5 program and need arrays like std::vector of c++

for example in my c++ code i have something like this:

class Neuron;
typedef std::vector<Neuron> Layer;
class net{
private:
std::vector<Layer> m_layers; //m_layers[layer_num][neuronum]
}

 how can i implement this in mql5 ? 

Rodrigo Malacarne
Moderator
9940
Rodrigo Malacarne 2014.07.25 13:56  
pumper:

Hi I'm working on a mql5 program and need arrays like std::vector of c++

for example in my c++ code i have something like this:

 how can i implement this in mql5 ? 

Please take a look at this Article and also at the Documentation.
Mohsen Khashei
621
Mohsen Khashei 2014.07.25 21:12  

thanks for reply it helped but not completly.

the problem remains is that in vector as i represented in my example every dimension can have its own data type even class objects but here for a 2d array all dim's are same data type.?

any idea? 

Alain Verleyen
Moderator
31085
Alain Verleyen 2014.07.28 15:36  
pumper:

thanks for reply it helped but not completly.

the problem remains is that in vector as i represented in my example every dimension can have its own data type even class objects but here for a 2d array all dim's are same data type.?

any idea? 

Your question is unclear. You can use a dynamic array in mql5, but only the first dimension can be dynamic.

How is it related to "data type" ?

Mohsen Khashei
621
Mohsen Khashei 2014.07.28 15:50  
angevoyageur:

Your question is unclear. You can use a dynamic array in mql5, but only the first dimension can be dynamic.

How is it related to "data type" ?

If you look at my code example of c++ and explain me how to do something like this in mql5 its my answer.(many thanks)
Alain Verleyen
Moderator
31085
Alain Verleyen 2014.07.28 15:54  
pumper:
If you look at my code example of c++ and explain me how to do something like this in mql5 its my answer.(many thanks)
I already answer you : with a dynamic array.
Uwe Goetzke
1483
Uwe Goetzke 2014.07.28 16:29  
class Neuron
{
  public:
double n1;
};

struct Layer{
 Neuron neurons[];
};

class net{
private:
Layer m_layers[]; //m_layers[layer_num][neuronum]
  public:
net()
{
   ArrayResize(m_layers,5);
   ArrayResize(m_layers[0].neurons,5);
}

double Get(int l, int n)
{
   return(m_layers[l].neurons[n].n1);
}

void Set(int l, int n, double val)
{
   m_layers[l].neurons[n].n1=val;
}
};

net * mynet;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
      mynet = new net();
      mynet.Set(0,3,3.14);
      Print(mynet.Get(0,3));
   }
 
Something similar to this... I think . Regards Uwe
Mohsen Khashei
621
Mohsen Khashei 2014.07.29 01:02  
ugo58:
Something similar to this... I think . Regards Uwe

thanks thats what exactly I looking for

and one more question : what performance comparition is in using c++ dll's instead of using fully mql5 EA's?

Uwe Goetzke
1483
Uwe Goetzke 2014.07.29 10:51  

Regarding perfomance that is difficult to judge.

You could use GetTickCount to measure the running time of  a complex part of code.

As with most systems the input/output of data is limiting factor for the design.

Interesting read for multi tasking:

https://www.mql5.com/en/articles/197


Regards  Uwe

Parallel Calculations in MetaTrader 5
Parallel Calculations in MetaTrader 5
  • 2011.03.02
  • Andrew
  • www.mql5.com
Time has been a great value throughout the history of mankind, and we strive not to waste it unnecessarily. This article will tell you how to accelerate the work of your Expert Advisor if your computer has a multi-core processor. Moreover, the implementation of the proposed method does not require the knowledge of any other languages besides MQL5.
To add comments, please log in or register