Why valenok2003 is against MT5 - page 24

 
tara: Not really.
Any for can be replaced by a corresponding while - and vice versa. And it is unlikely that any of these constructs will be clearly more economical than the other.
 
Mathemat:
Any for can be replaced by a corresponding while - and vice versa. And it is unlikely that either of these constructs is clearly more economical than the other.
Any for and while can be replaced by goto with faster code execution.
 
Zhunko: Any for and while can be replaced by goto to speed up code execution.
An example, Vadim? Don't do asm, let's do something in C.
 
Mathemat:
An example, Vadim? Don't give me asm, give me something in C.
      // 1.1.1. Метод копирования данных по указателю до 128 Гб.
      template<class type1, class type2> // Любые типы.
      static void Copy(      type1*  pt1Dest,        // Указатель на приёмник данных.
                       const DWORD64 dw64SizeDest,   // Размер приёмника данных в байтах.
                             type2*  pt2Source,      // Указатель на источник данных.
                       const DWORD64 dw64SizeSource, // Размер источника данных в байтах, начиная от указателя pt2Source.
                             DWORD64 dw64Count)      // Количество копируемых данных в байтах.
       {
        PBYTE pbtDest = PBYTE(pt1Dest);     // Инициализируем локальный указатель на приёмник.
        PBYTE pbtSource = PBYTE(pt2Source); // Инициализируем локальный указатель на источник.
        // Корректируем количество копируемых байт под размер источника.
        dw64Count = COUNT_DIRECT(_T("Utils::Memory::Simple::Copy"), dw64SizeSource, 0, dw64Count);
        dw64Count = Min(dw64Count, dw64SizeDest);
        // Для количества данных более или равно 2147483647 байт цикл необходим.
        if (dw64Count >= sizeof(BYTES_0X7FFFFFFF))
         {
          DWORD64 i = 0;
          DWORD64 dw64Iterations = Utils::Math::Arithmetic::DivideFloor(dw64Count, sizeof(BYTES_0X7FFFFFFF)); // Количество итераций. Округляем в меньшую сторону.
          START: if (!SimpleCopy<BYTES_0X7FFFFFFF>(pbtDest, pbtSource, dw64Count)) return;
          i++;
          if (i < dw64Iterations) goto START;
         }
        if (!SimpleCopy<BYTES_0X40000000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X20000000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X10000000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X8000000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X4000000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X2000000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X1000000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X800000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X400000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X200000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X100000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X80000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X40000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X20000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X10000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X8000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X4000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X2000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X1000>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X800>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X400>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X200>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X100>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X80>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X40>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X20>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X10>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X8>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X4>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X2>(pbtDest, pbtSource, dw64Count)) return;
        if (!SimpleCopy<BYTES_0X1>(pbtDest, pbtSource, dw64Count)) return;
       }
Tried to get rid of unnecessary loops. This code works 20% faster than standard memcpy. It also doesn't limit copy size and is safer than memcpy.
 

Thank you. As far as I understand, the main construction that should work faster is this one:

START: if (!SimpleCopy<BYTES_0X7FFFFFFF>(pbtDest, pbtSource, dw64Count)) return;
i++;
if (i < dw64Iterations) goto START;

Well, this is the while emulation. Yes, it is quite possible that it is faster than the standard loop. But probably only at the expense of slower initialization time of the controlling construct itself.

And how many iterations are there in this "loop"?

 

A little faster.

 

Hee:)

 
Roman.:
In principle, yes. Assembler has jmp. So what was it designed for?
Assembler also has "nop", so what?
 
goto is very versatile. It replaces for , while and break. It's much better to get out of a multiple nested goto loop than to add a break condition to each nested loop.
 

goto is a great substitute where there are no exceptions, but you need something like a finally block.

Of course, ifs are good too, but goto is probably even more elegant.

But generally speaking, there is no sense in eating spaghetti with a toothpick if you have a normal fork.

And the programmer who will pick up the code after you won't pat on the head.