Errors, bugs, questions - page 816

 
In my opinion, this is just an optimisation of the first case of direct access to an object member.

In the second case there is indirect access via reference, which in a microscopic loop body naturally takes half the time, doubling it.
Документация по MQL5: Основы языка / Типы данных / Структуры и классы
Документация по MQL5: Основы языка / Типы данных / Структуры и классы
  • www.mql5.com
Основы языка / Типы данных / Структуры и классы - Документация по MQL5
 
The test is somewhat incorrect, essentially comparing the difference between a single assembler instruction and two assembler instructions placed in a hundred million loops.
 
Renat:
I think this is just an optimization of the first case of direct access to an object member.

In the second case we have indirect access via reference which naturally takes half of the time with a microscopic loop body increasing it twofold.

Renat, in the real world there are large arrays of data being processed. I have already simplified the test, just to show the problem area. Initially I created it using my own arrays and classes. Then I reduced it to a scheme.

i.e. we don't actually have just one arr object, but an array of complex objects (also with arrays).

roughly this can be written in the scheme as

class A
{
  double prm1;
  int prm2;
  string prm3;
  char prm4;
}

class B
{
   A m_a[1000];
}

B _b[1000];



I reasoned that if I get a reference to a particular array element A

А *item=GetPointer(_b[i]._a[j]);

The work with parameters A::prmX will be faster.


But it turned out that pulling a sausage out of array names

_b[i]._a[j].prmX  

would be at least twice as fast as referring to a particular item.

I was a bit surprised by this, and it's clear that the kernel is getting some kind of pseudo-pointer.

Is there any way to optimize the speed, which at least reduces the difference in speed?

 
sergeev:

this is how it will be without errors

There will be no errors in this test. But this method does not solve the main question: why does the compiler skip transformation of a constant object reference to a non-constant reference without generating any errors and/or warnings? If it is such a feature, no questions, but in this case the meaning of the const modifier for the returned type in the signature of class methods is lost.
 
mvk:
There will be no error in this way in this test. But this method does not solve the main question: why does the compiler skip transformation of a constant object reference to a non-const reference and generate no error and/or warning? If it is such a feature, no questions, but in this case the meaning of the modifier const for the returned type in the signature of class methods is lost.

everything makes sense to me.

The constant object functions should not change the object itself, so they should also have a const modifier

and about

   //Ошибки нет. Это НЕ правильно(CONST A* B::getA())!
   A* a2 = b.getA();

well, yes, that won't work in C++.

Write to servicedesk.

 
sergeev:

But it turns out that pulling a sausage out of array names

will be at least twice as fast as accessing a specific item.

Is it really faster or is it a logical construction of the output based on other simpler cases?

In my opinion, a clean proof based on the presented access to a multidimensional array has not been presented yet. Especially given the presence of the frankly expensive additional function GetPointer.


It surprised me a bit, and it became clear that there is some kind of pseudo-indexing going on in the kernel.

Pointers in the conventional sense do not exist in MQL5, they are handles, with all their consequences.


Is there any way to optimize the speed, which would at least reduce the speed difference?

We are constantly working on optimisation, but in the case of references/handles there is a system overhead on indirect access.

Anyway, let's look more closely into optimization of such access.

Документация по MQL5: Основы языка / Переменные
Документация по MQL5: Основы языка / Переменные
  • www.mql5.com
Основы языка / Переменные - Документация по MQL5
 
Renat:

Is it really faster or is it a logical construction of the conclusion based on other simpler cases?

yes, it's quite realistic. i've tested it on filling my arrays. it's always been twice as slow.

To my mind, a clean proof based on the presented multidimensional array access has not yet been presented.

Well, I've laid out the scheme and an image of classes A, B and arrays.


Especially with the frankly expensive additional function GetPointer.

it is called once before entering a loop. but in principle, for a more accurate test, you can also take it outside of GetTickCount

In any case, we will take a closer look at optimizing such access.

OK. Thanks. That's exactly what we need.

 
sergeev:

it is called once before entering the loop. but in principle, for a more accurate test, you could also take it outside of GetTickCount

How about outside the loop if the code is like this?
А *item=GetPointer(_b[i]._a[j]);
 
A suggestion. Can the text zoom feature be included in the help, e.g. + or - , or Ctrl+mouse wheel.
 
paladin800:
A suggestion. Can the text zoom feature be included in the help. e.g. + or - , or Ctrl+mouse wheel.

It's probably not possible. Isn't the online version suitable?

Here's what I found on the internet on the subject - http://forum.ru-board.com/topic.cgi?forum=62&topic=20907

UPDate More http://forum.ixbt.com/topic.cgi?id=23:39211

Невозможно изменить размер шрифта при просмотре .CHM файлов. :: Microsoft Windows :: Компьютерный форум Ru.Board
  • forum.ru-board.com
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору
Reason: