Questions on OOP in MQL5 - page 69

 
fxsaber:
I got an unexpected result.


imho, the tests are not comparable

STRUCT2 has a constructor

STRUCT2 has strings

there is no documentation about strings as implemented in MQL, we discussedhttps://www.mql5.com/ru/forum/1111/page2732#comment_16181920


i.e. in your test, STRUCT2 works as a class with a constructor, which has a "string class" with a constructor, which is in effect allocating memory for the object several times

I think such a complex test must be broken down into several tests - the time of creating STRUCT1 and STRUCT2 structures and then the time of accessing data. Some developers wrote that string is allocated memory only after accessing string - in your example, string is initialized by a constant string, so it is hard to see how it is initialized - the compiler may not initialize (or allocate memory?) arrays of strings before accessing them

 
Igor Makanu:

I think such a complex test should be broken down into several tests

I don't even want to bother. I made simple structures.

#include <fxsaber\Benchmark.mqh> // https://c.mql5.com/3/321/Benchmark.mqh

// Простая структура.
struct STRUCT1
{
  int i;
  double j[2];
};

// Простая структура большего размера.
struct STRUCT3
{
  int i;
  double j[10];
};

template <typename T>
int Func( T &Array[] )
{  
  // Write
  for (int i = ArraySize(Array) - 1; i >= 0; i--)
    Array[i].i = i;

  int Sum = 0;
  
  // Read
  for (int i = ArraySize(Array) - 1; i >= 0; i--)
    Sum += Array[i].i;
    
  return(Sum + ArraySize(Array));    
}

#include <Debug.mqh>

void OnStart()
{
  STRUCT1 Array1[]; // Простая структура.
  STRUCT3 Array3[]; // Простая структура большего размера.
  
  const int Amount = 5 e7;
  
  Print(_B(ArrayResize(Array1, Amount), 1));
  Print(_B(ArrayResize(Array3, Amount), 1));
      
  Print(_B(Func(Array1), 1)); // Чтение и запись простой структуры
  Print(_B(Func(Array3), 1)); // зависит от ее размеров.
  
  _P2(sizeof(STRUCT1));
  _P2(sizeof(STRUCT3));
}


        50000000
        50000000
        Alert: Time[Test6.mq5 280: Func(Array1)] = 312 ms.
        1333106752
        Alert: Time[Test6.mq5 281: Func(Array3)] = 1348 ms.
        1333106752
        : sizeof(STRUCT1) = 20
        : sizeof(STRUCT3) = 84


For what reason access to the first field of a simple structure depends on its size - is not clear.

 
fxsaber:

I don't even want to bother. I made simple structures.



For what reason access to the first field of a simple structure depends on its size - is not clear.

It is better to ask this question to developers in the corresponding branch. With test code. Either they will explain it, or they will fix it, or they won't say anything... Only the third variant will probably work here.

 
Artyom Trishkin:

This is a question best posed to the developers in the relevant branch. With the test code. Either they will explain it, or they will fix it, or they will say nothing... Here is probably only the third option.

My MT5 has started to cause too much profanity. There are critical bugs. This is bullshit.

 
fxsaber:

I don't even want to bother. I have made simple structures.

now the same STRUCT1 and STRUCT3 tests

fxsaber:

I do not understand why access to the first field of a simple structure depends upon its size.

This is just a guessing game.

another way is to wait for someone to do the same test in C++ and display the results. If there is a big difference, it means that memory allocation in MQL is poorly implemented

if tests 1 and 2 are about the same, it is Windows that is allocating memory this way

 
fxsaber:

My MT5 has started to cause too much profanity. There are critical bugs. This is bullshit.

It is advisable to report all bugs. Critical and not. Emotionless, of course :)

 
Igor Makanu:

if tests 1 and 2 are about the same, then that's the way Windows is allocating memory

ran the last test 2 times on

Terminal MetaTrader 5 x64 build 2470 started for MetaQuotes Software Corp.

Windows 10 build 18363, Intel Core i3-4170 @ 3.70GHz, 8/11GB memory, 188/297GB disk, IE 11, UAC, GMT+4

2020.05.30 17:01:27.996 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 53: ArrayResize(Array1,Amount)] = 1 ms.

2020.05.30 17:01:27.996 tst_f (EURUSD,H1) 50000000

2020.05.30 17:01:28.002 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 54: ArrayResize(Array3,Amount)] = 6 ms.

2020.05.30 17:01:28.002 tst_f (EURUSD,H1) 50000000

2020.05.30 17:01:28.515 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 56: Func(Array1)] = 512 ms.

2020.05.30 17:01:28.515 tst_f (EURUSD,H1) 1333106752

2020.05.30 17:01:30.734 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 57: Func(Array3)] = 2218 ms.

2020.05.30 17:01:30.734 tst_f (EURUSD,H1) 1333106752

2020.05.30 17:01:41.278 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 53: ArrayResize(Array1,Amount)] = 2 ms.

2020.05.30 17:01:41.278 tst_f (EURUSD,H1) 50000000

2020.05.30 17:01:41.287 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 54: ArrayResize(Array3,Amount)] = 9 ms.

2020.05.30 17:01:41.287 tst_f (EURUSD,H1) 50000000

2020.05.30 17:01:41.840 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 56: Func(Array1)] = 552 ms.

2020.05.30 17:01:41.840 tst_f (EURUSD,H1) 1333106752

2020.05.30 17:01:43.728 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 57: Func(Array3)] = 1888 ms.

2020.05.30 17:01:43.728 tst_f (EURUSD,H1) 1333106752


not all files are attached to the script, last lines did not compile

  //_P2(sizeof(STRUCT1));
//  _P2(sizeof(STRUCT3));

I had the Debug.mqh includer


UPD: on old build I ran the test

2020.05.30 17:17:27.604 Terminal MetaTrader 5 - build 2361



2020.05.30 17:13:17.046 tst (EURUSD,H1) Alert: Time[tst.mq5 53: ArrayResize(Array1,Amount)] = 1 ms.

2020.05.30 17:13:17.047 tst (EURUSD,H1) 50000000

2020.05.30 17:13:17.053 tst (EURUSD,H1) Alert: Time[tst.mq5 54: ArrayResize(Array3,Amount)] = 6 ms.

2020.05.30 17:13:17.053 tst (EURUSD,H1) 50000000

2020.05.30 17:13:17.563 tst (EURUSD,H1) Alert: Time[tst.mq5 56: Func(Array1)] = 510 ms.

2020.05.30 17:13:17.563 tst (EURUSD,H1) 1333106752

2020.05.30 17:13:19.416 tst (EURUSD,H1) Alert: Time[tst.mq5 57: Func(Array3)] = 1852 ms.

2020.05.30 17:13:19.416 tst (EURUSD,H1) 1333106752

2020.05.30 17:13:28.971 tst (EURUSD,H1) Alert: Time[tst.mq5 53: ArrayResize(Array1,Amount)] = 2 ms.

2020.05.30 17:13:28.971 tst (EURUSD,H1) 50000000

2020.05.30 17:13:28.977 tst (EURUSD,H1) Alert: Time[tst.mq5 54: ArrayResize(Array3,Amount)] = 6 ms.

2020.05.30 17:13:28.977 tst (EURUSD,H1) 50000000

2020.05.30 17:13:29.456 tst (EURUSD,H1) Alert: Time[tst.mq5 56: Func(Array1)] = 478 ms.

2020.05.30 17:13:29.456 tst (EURUSD,H1) 1333106752

2020.05.30 17:13:31.192 tst (EURUSD,H1) Alert: Time[tst.mq5 57: Func(Array3)] = 1735 ms.

2020.05.30 17:13:31.192 tst (EURUSD,H1) 1333106752

the results are similar - the behaviour is the same
 
Try swapping their adverts. Doesn't it depend on which one is at the top of the stack?
 
Artyom Trishkin:

All bugs should preferably be reported. Critical or not. Unemotionally of course :)

Detailed branches have been created.

 
Vladimir Simakov:
Try swapping their announcements. Doesn't it depend on which one is at the top of the stack?
void OnStart()
{
  STRUCT3 Array3[]; // Простая структура большего размера.
  STRUCT1 Array1[]; // Простая структура.
  
  
  const int Amount = 5 e7;
  
  Print(_B(ArrayResize(Array3, Amount), 1));
  Print(_B(ArrayResize(Array1, Amount), 1));
  
      
  Print(_B(Func(Array3), 1)); // зависит от ее размеров.
  Print(_B(Func(Array1), 1)); // Чтение и запись простой структуры
  
  //_P2(sizeof(STRUCT1));
//  _P2(sizeof(STRUCT3));
}

2020.05.30 17:33:07.892 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 54: ArrayResize(Array3,Amount)] = 6 ms.

2020.05.30 17:33:07.955 tst_f (EURUSD,H1) 50000000

2020.05.30 17:33:07.957 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 55: ArrayResize(Array1,Amount)] = 1 ms.

2020.05.30 17:33:07.957 tst_f (EURUSD,H1) 50000000

2020.05.30 17:33:09.902 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 58: Func(Array3)] = 1945 ms.

2020.05.30 17:33:09.902 tst_f (EURUSD,H1) 1333106752

2020.05.30 17:33:10.353 tst_f (EURUSD,H1) Alert: Time[tst_f.mq5 59: Func(Array1)] = 450 ms.

2020.05.30 17:33:10.353 tst_f (EURUSD,H1) 1333106752

Doesn't seem to make any difference to me.