Errors, bugs, questions - page 2195

 
Artyom Trishkin:

Greetings from fxsaber:

Can we see a picture - what does it (the code) do?

 

Please explain why ArrayResize is very slow with a reserve task?

Script

// Добавление элемента в конец произвольного массива
template <typename T>
void AddElement( T &Array[], const T &Value, const int Reserve = 0 )
{
  const int Size = ::ArraySize(Array);

  ::ArrayResize(Array, Size + 1, Reserve);

  Array[Size] = Value;
}


#define  BENCH(A)                                                              \
{                                                                             \
  const ulong StartTime = GetMicrosecondCount();                              \
  A;                                                                          \
  Print("Time[" + #A + "] = " + (string)(GetMicrosecondCount() - StartTime)); \
}

int Bench( const int Size, const int Reserve )
{
  const MqlTick NullTick = {0};
  MqlTick Ticks[];  
  
  for (int i = 0; i < Size; i++)
    AddElement(Ticks, NullTick, Reserve);
    
  return(ArraySize(Ticks));
}

void OnStart()
{
  BENCH(Bench(1 e7, 1 e5)); // 100 раз выделяется память
  BENCH(Bench(1 e7, 1 e6)); //  10 раз выделяется память
  BENCH(Bench(1 e7, 1 e7)); //   1 раз выделяется память
}


Result

Time[Bench(1 e7,1 e5)] = 38199494
Time[Bench(1 e7,1 e6)] = 3867983
Time[Bench(1 e7,1 e7)] = 479303


100 times memory allocation (5 Mb to 500 Mb) takes 38 seconds. Is it normal?

Practical application is in custom characters, when you want to prepare a tick history before importing. Suppose, there are some CSV-files with tick data in the local storage, and you need to make a MqlTick-array of them. How to do it in an optimal way? It is impossible to calculate in advance the amount of ticks in these files.

 
Rashid Umarov:

Can we see a picture - what does it (the code) do?

 
fxsaber:

It is not possible to calculate the number of ticks in these files in advance.

Divide the file size by the approximate size of one tick?

 
Andrey Khatimlianskii:

Divide the file size by the approximate size of one tick?

Unfortunately, I don't know the file sizes - I unpack the CSV from a ZIP.

 
Rashid Umarov:

Can we see a picture - what does it do?

Making a screenshot over a selected time period has proved difficult - maybe there is a proper width definition solution to capture the bars over the two date ranges inclusive?

 
Aleksey Vyazmikin:

Making a screenshot over a selected time period has proved difficult - is there a proper width definition solution to capture the bars over the two date ranges inclusive?

What's the difficulty? I made 2 screenshots with different scales in one script so that the screenshot shows 30 bars from the specified date.


 
fxsaber:

Unfortunately, I don't know the file sizes - I decompress the CSV from ZIP.

Where do they go from ZIP? Into an array? To a string? They have a size/length too.

 
Alexey Viktorov:

What are the difficulties? Here is one script made 2 screenshot with different scale so that on the screen was 30 bars from the specified date.


Put the zoom to zero, even now you can see that in the second screenshot the bar is already tight, unlike in the first one.

And what is 30 bars, let's make it 600!
 
Andrey Khatimlianskii:

Where do they go from the ZIP? Into an array? To a string? They have a size/length, too.

Then I would have to decompress everything and keep hundreds of megabytes of unpacked stuff in memory.

Or unpack by adding up the number of strings (string - tick). Saving on memory. And then decompress again, but with parsing.

Reason: