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

 
fxsaber #:

In all constructors/destructors, write this line.

Then you will see the sequence of all calls in the log. And the picture will be formed.

or it will break :-)

when the "default constructor" is called without warning and declaration of war....

PS/ C++, Pascal, whatever, but should be BEFORE mql.

 
Maxim Kuznetsov #:

PS/ C++, Pascal, whatever, but should DO mql.

I know only MQL5 - normal flight.

 

The optimal array type for reading byte information is uint[].

uint Calc( uint Num ) { return((Num & 0xFF) + ((Num >>= 8) & 0xFF) + ((Num >>= 8) & 0xFF) + (Num >>= 8)); }

void OnStart()
{
  uchar Array1[];
  uint Array2[];
  
  const int Size1 = ArrayResize(Array1, INT_MAX / sizeof(uint) * sizeof(uint));
  const int Size2 = ArrayResize(Array2, Size1 / sizeof(uint));
  
  const uchar Tmp = 1;  
  ArrayInitialize(Array1, Tmp);
  ArrayInitialize(Array2, ((uint)Tmp << 24) | ((uint)Tmp << 16) | ((uint)Tmp << 8) | Tmp);
  
  {
    const ulong StartTime = GetMicrosecondCount();
    uint Sum = 0;
    
    for (int i = 0; i < Size1; i++)
      Sum += Array1[i];
    
    Print(GetMicrosecondCount() - StartTime); // 1171900
    Print(Sum);
  }

  {
    const ulong StartTime = GetMicrosecondCount();
    uint Sum = 0;
    
    for (int i = 0; i < Size2; i++)
      Sum += Calc(Array2[i]);
    
    Print(GetMicrosecondCount() - StartTime); // 796638
    Print(Sum);
  }
}

It is interesting that AVX-code is slower than x64-code.

 
fxsaber #:

The optimal array type for reading byte information is uint[].

Try ulong.
 
Alain Verleyen #:
With compiler optimisation?

Yes.

Alain Verleyen #:
Try using ulong.

I tried different variants: ulong, struct, union. The best of the lowers showed performance like uint.

 
fxsaber #:

Yes.

I tried different variants: ulong, struct, union. The best of the lowers showed performance like uint.

2025.10.29 08:53:45.911    393227-3143 (EURUSD,H1)    X64 Regular UCHAR:     391609 : 2147483640
2025.10.29 08:53:46.198    393227-3143 (EURUSD,H1)    X64 Regular UINT:        287708 : 2147483640
2025.10.29 08:53:46.487    393227-3143 (EURUSD,H1)    X64 Regular UNION32:  288293 : 2147483640
2025.10.29 08:53:46.681    393227-3143 (EURUSD,H1)    X64 Regular UNION64:  193904 : 2147483640
2025.10.29 08:53:46.928    393227-3143 (EURUSD,H1)    X64 Regular ULONG:    246861 : 2147483640

2025.10.29 08:55:48.715    393227-3143 (EURUSD,H1)    AVX UCHAR:                401309 : 2147483640
2025.10.29 08:55:49.005    393227-3143 (EURUSD,H1)    AVX UINT:                   290088 : 2147483640
2025.10.29 08:55:49.296    393227-3143 (EURUSD,H1)    AVX UNION32:             290388 : 2147483640
2025.10.29 08:55:49.490    393227-3143 (EURUSD,H1)    AVX UNION64:             194669 : 2147483640
2025.10.29 08:55:49.756    393227-3143 (EURUSD,H1)    AVX ULONG:                265811 : 2147483640

Files:
 
I don't see any array vectorization code. That's why AVX did not decrease the execution time 

 
amrali #:
I don't see any array vectorization code. That's why AVX did not decrease the execution time 

Sure. But it increased it (a bit).
 
Hello. I need help with solving the symbol no found error. I tried several things but still not working. Please help. Thanks a lot
 
Vladimir Pastushak #:
I read somewhere about constructors and destructors. The order of creation and destruction, but I can't find it....
https://www.mql5.com/en/docs/basis/variables/object_live