Features of the mql5 language, subtleties and tricks - page 286

 
Andrey Khatimlianskii #:

I think it's just not the optimal reserve in ErrayResize that is used inside FileLoad.

template <typename T>
int FileLoad2( const string FileName, T &Data[] )
{
  int Res = -1;
  
  const int Handle = FileOpen(FileName, FILE_READ | FILE_BIN);
  
  if (Handle != INVALID_HANDLE)
  {
    Res = (int)FileReadArray(Handle, Data, 0, ArrayResize(Data, (int)FileSize(Handle) / sizeof(T)));
    
    FileClose(Handle);
  }
  
  return(Res);
}

It's unambiguous there

 
Andrey Khatimlianskii #:

I think, just not optimal reserve in ArrayResize is used inside FileLoad.

Why "not optimal" ? You have 1000 ArrayResize versus 1 static array, it's perfectly normal result.
 
Alain Verleyen #:
Why "not optimal"? You have 1000 ArrayResize vs 1 static array, this is a perfectly normal result.

1000 ArrayResize should take 15 milliseconds (since my test shows that a single ArrayResize takes ~15 microseconds)

void OnStart()
  {
   MqlTick Ticks[];
   ulong tickcount = GetMicrosecondCount();
   ArrayResize(Ticks, 2000000 + tickcount % 10);
   ulong spent = GetMicrosecondCount() - tickcount;
   Print("Time spent resizing array: ", spent, " microseconds");
   //--- Everything below is an attempt to avoid compiler optimizations
   for(int i = ArraySize(Ticks) - 1; i >= 0; i--)
     {
      int r = MathRand() % 5;
      Ticks[i].time = ++r;
      Ticks[i].bid = ++r * _Point;
      Ticks[i].ask = ++r * _Point;
      Ticks[i].last = ++r * _Point;
      Ticks[i].volume = ++r;
      Ticks[i].time_msc = ++r;
      Ticks[i].flags = ++r;
      Ticks[i].volume_real = ++r;
     }
   MqlTick sum;
   for(int i = ArraySize(Ticks) - 1; i >= 0; i--)
     {
      sum.time += Ticks[i].time;
      sum.bid += Ticks[i].bid;
      sum.ask += Ticks[i].ask;
      sum.last += Ticks[i].last;
      sum.volume += Ticks[i].volume;
      sum.time_msc += Ticks[i].time_msc;
      sum.flags += Ticks[i].flags;
      sum.volume_real += Ticks[i].volume_real;
     }
   Print(sum.time, sum.bid, sum.ask, sum.last, sum.volume, sum.time_msc, sum.flags, sum.volume_real);
  }
 
Vladislav Boyko #:

1000 ArrayResize should take 15 milliseconds (since my test shows that a single ArrayResize takes ~15 microseconds)

That's wrong reasoning.
 
fxsaber #:

It's a shame that working with data in mat mode is more theory than practice.

This is a peculiarity of the tester in general, not of the mat mode - the optimised program is loaded by the agent once for efficiency purposes, as far as I know.

 
Stanislav Korotky #:

This is a feature of the tester in general, not of the mat.mode - the optimised program is loaded by the agent once for efficiency purposes, as far as I know.

But this programme has to load data at each pass.

 
fxsaber #:

But this programme has to load the data on every pass.

I assume that the described empty (or rather, "rubbish" because it is not initialised with anything) global array is allocated only once - during loading before the first pass. The point was that it seems to waste extra time on memory reallocation in case of a dynamic array, while here there are no such repetitive costs.

 

Hello everyone, I'm pretty new here..

I am having some problems using templates when writing the function body outside the function class. I've already looked in the documentation but I didn't find anything related to this..

Compiling this code I am getting the following error: "function 'Test::test' already defined and has different return type"

template<typename any>
struct Optional {
    any value;
};

class Test {
public: 

    template<typename any>
    Optional<any>    test();

};

template<typename any>
Optional<any> Test::test() {
    return Optional<any>();


But, if I write the function body inside the class I get no error:

template<typename any>
struct Optional {
    any value;
};

class Test {
public: 

    template<typename any>
    Optional<any> test() {
        return Optional<any>();
    }

};

Could someone help me to understand how to solve this problem? (I don't want to mark the whole class as template)



 
Paolo Besana #:

Compiling this code, I get the following error: " function 'Test::test' is already defined and has a different return type".

This is a bug in MQL5, everything is fine in MQL4. Write a bug report.
 
It looks like a bug. At least it compiles normally in C++. Try to post in this thread.
Новая версия платформы MetaTrader 5 build 4755: общие улучшения - После обновления платформы MetaTrader 5 мы исправили ошибку в расчете тройного свопа, происшедшую при некоторых сочетаниях условий тестирования.
Новая версия платформы MetaTrader 5 build 4755: общие улучшения - После обновления платформы MetaTrader 5 мы исправили ошибку в расчете тройного свопа, происшедшую при некоторых сочетаниях условий тестирования.
  • 2024.12.13
  • MetaQuotes
  • www.mql5.com
Радиус примагничивания курсора мыши при выделении графических объектов. Надо просто добавить установочные файлы в исключения этого антивирусника и Некоторые проблемы с отрисовкой и срабатыванием контролов тестера. Зависает Play видно по кликам которые сопровождаются желтым кружком. Ползунок пропадает и вместо него выводится Tooltip контрола