Help with OOP - page 5

 

I need to write something here too...

I have such a thing in my code:

   union u_Data_t
     {
      T value;
      ulong data[sizeof(T)/8+1];
     } data_t;

T is int type.

Execution time of the function 10*1024*1024 times under debugging: 214.659 milliseconds.

Without debugging: 13190.941 milliseconds

There is no error here, the release version is much slower.

Let's change the variable declaration a bit:

   static union u_Data_t
     {
      T value;
      ulong data[sizeof(T)/8+1];
     } data_t;

It appears static.

Under debugging: 213.045 milliseconds.

Without: 70.237milliseconds

 
Vasiliy Sokolov #:
Dmitry, excuse me, do you know any programming language other than mukl? No, you don't. And you still haven't learned how to work with objects and pointers, it's clear from those few codes and even articles you've published. That's why I cannot even seriously reply to this talentless and frankly stupid comment. Read wikipedia at last, learn what a rubbish collector is and how it is organized, finally read at least once what you are trying to refer to. So far, it all looks like a dog barking at a caravan: senseless and merciless.

Deal with your own cockroaches first. It's funny, you're too inadequate. And that's me being modest))

You can't answer anything seriously because you can't answer anything seriously at all, because you're muddy.

Vasily, you really are inadequate. After all, this talk about the rubbish collector was a year ago, if not more. It's still there,

you haven't figured out what it is in a year. I mean, I don't know if you've got a clue what it is, but you've demonstrated here

that you don't understand, banally, the topic of the conversation, and you contradict yourself. And the amazing thing is that you seem to know at least

two languages, one of them with a rubbish collector, and even so, you don't know the difference between a language with a rubbish collector

and a language without a rubbish collector.

And answer for your words - show me how I don't know how to work with objects and pointers?

 
Aliaksandr Hryshyn #:

the release version is significantly slower.

Ready code for playback?

 
fxsaber #:

Ready-made code to play?

//+------------------------------------------------------------------+
//|                                                        cBool.mqh |
//|                                               Aliaksandr Hryshyn |
//|                          https://www.mql5.com/ru/users/greshnik1 |
//+------------------------------------------------------------------+
#property copyright "Aliaksandr Hryshyn"
#property link      "https://www.mql5.com/ru/users/greshnik1"

//Битовый поток
class cBit_thread
  {
private:
   ulong             _bit_thread[];//Битовый поток данных
   uint              _bit_thread_size;//Количество записанных бит в потоке
   uint              _bit_thread_pos;//Текущя позиция для чтения/записи
public:
   //Запись последовательности бит
   //Размер увеличивается динамически
   template<typename T>
   int               Write(
      const T value,//Простая структура или переменная
      uint pos_bit_read=0,//С какой позиции начать считывание из структуры/переменной.Указывается в битах
      int bits_count=-1//Количество бит. -1=все до конца
   );//Возвращает количество записанных бит -1=ошибка
  };

template<typename T>
int cBit_thread::Write(const T value,uint pos_bit_read=0,int bits_count=-1)
  {
   static union u_Data_t
     {
      T value;
      ulong data[sizeof(T)/8+1];
     } data_t;
   ZeroMemory(data_t.data);
   data_t.value=value;

   if(pos_bit_read>=sizeof(T)*8)
      return -1;
   if(bits_count<0)
      bits_count=int(sizeof(T)*8-pos_bit_read);
   else
      if(pos_bit_read+bits_count>sizeof(T)*8)
         return -1;

   uint shift=int(pos_bit_read&63);
   int read_from=int(pos_bit_read>>6);

   int read_end=int(pos_bit_read+bits_count);
   uint write_to=0;
   ulong l1=0;
   for(int i1=read_from; i1<(read_end>>6)+1; i1++,write_to++)
     {
      l1=data_t.data[i1];
      data_t.data[write_to]=l1>>shift;
      if(write_to>0)
         data_t.data[write_to-1]|=l1<<(64-shift);
     }

   uint len1=ArrayRange(_bit_thread,0);
   uint len2b=_bit_thread_pos+bits_count;
   if(len2b+128>(len1<<6))
     {
      len2b=(len2b>>6)+2;
      ArrayResize(_bit_thread,len2b+1024);
      len2b+=1024;
      for(uint i1=len1; i1<len2b; i1++)
         _bit_thread[i1]=0;
     }
   int pos_end=(bits_count>>6)+((bits_count&63)!=0);
   shift=_bit_thread_pos&63;
   write_to=(_bit_thread_pos>>6);
   if(shift==0)
     {
      for(int i1=0; i1<pos_end; i1++)
        {
         l1=data_t.data[i1];
         _bit_thread[write_to]|=l1;
        }
     }
   else
     {
      for(int i1=0; i1<pos_end; i1++)
        {
         l1=data_t.data[i1];
         _bit_thread[write_to]|=(l1<<shift);
         _bit_thread[write_to+1]|=l1>>(64-shift);
        }
     }
   _bit_thread_pos+=bits_count;
   _bit_thread_size=MathMax(_bit_thread_size,_bit_thread_pos);
   return bits_count;
  }
//+------------------------------------------------------------------+

And a script:

#include <cBool.mqh>
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   cBit_thread thread;
   ulong mcs=GetMicrosecondCount();
   int num=1;
   for(int i1=0; i1<10*1024*1024; i1++)
     {
      thread.Write(num,0,1);
     }
   Print((GetMicrosecondCount()-mcs)/1000.0);
  }
 
Has anyone done this?
 
Aliaksandr Hryshyn #:

And the script:

Release: 81.003
Debug: 295.312

I don't see the problem.

 
fxsaber #:

I don't see the problem.

Latest beta 3062

 
My 229 and 225 are exactly the same.
 
Dmitry Fedoseev #:
I have 229 and 225 - exactly the same.

Is the terminal version the same?

 
Aliaksandr Hryshyn #:

Is the terminal version the same?

3061