Errors, bugs, questions - page 2468

 
Alexey Navoykov:

The pseudo code they gave in this thread some time ago, look for it. As far as I remember, the capacity there is increased only when the array size exceeds this capacity. Although something could have changed of course.

And the function to get the value of saracity is really very necessary.

Thanks for the information, so far I found how fxsaber was looking for the same thing )).

Forum on trading, automated trading systems and strategy testing

Bugs, bugs, questions

fxsaber, 2018.04.13 10:04

Help find the developer post where the ArrayResize source code was posted. Googling "site:mql5.com/en/forum ArrayResize+reserve" doesn't help.

I remember that there was a source code. In it you can immediately see the logic of implementation of the reserve-parameter.

I searched on google, I searched on forum, I searched in profiles of main developers...
Besides possibility to use reserve_size with value -1 in ArrayResize to clear previously allocated memory, I haven't found anything.
 
Sergey Dzyublik:

Thanks for the information, so far I found how fxsaber was looking for the same thing ))

I haven't found it either.)

I think @Slava wrote about it.

 

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Ilyas, 2016.08.24 11:08

The array ("inside") stores the allocated - under how many elements the array is allocated.

The logic for working with allocated (conditional code):
ArrayResize(arr,int size,int reserve)
  {
   if(arr.allocated<size)
      if(!ArrayAllocateMemory(arr,size+reserve))  // -> arr.allocated=size+reserve;
         return(-1);
   //---
   CallConstructorsOrDestructors(arr,size);
   //---
   arr.size=size;
   return(size);
  }

 
Alexey Navoykov:

Thank you for your help.
Unfortunately, this code does not provide any answers to the questions at hand.

 
class A{
   uchar data;
};
 
template<typename T>
class B{
public:
   T data;
};

template<typename T>
class C {
public:
   uchar data;
};


void OnStart(){
   A a;
   B<A> b;
   C<A> c;
   
   a = (A)(a);
   b = (B<A>)(b);    //'(' - invalid cast operation
   c = (C<A>)(c);    //code generation error            
}
Not all data types can perform a type cast "in itself", it turns out...
Template classes break at compile time, but structures are OK.
 
You can pull out the reserve with dirty hooks and check resize behaviour with the handles
 
TheXpert:
You can get the reserve with dirty hooks and check the resize behavior with handles

Presumably, in the array object's memory, the variable under reserved size lies next to the variable under size.
But at the moment there are ten more urgent tasks than debugging or digging in memory of MT to study the effect of ArrayResize on the reserved size field of the array object.

 
Sergey Dzyublik:
#import "msvcrt.dll"
  long memcpy(int &dst[], long &src, int cnt);
#import

struct ArrayStore
{
   long offset;
   double x[];
   
   int capacity() 
   {
      int ints[sizeof(ArrayStore) / sizeof(int)];
      memcpy(ints, this.offset, sizeof(ArrayStore));
      return ints[8];
   }
};

void OnStart()
{
   ArrayStore store;
   ArrayResize(store.x, 17, 8755);
   Print("all reserved size = ", store.capacity()); // 8772
}
 
Sergey Dzyublik:
Not all data types can perform a type cast "in itself", it turns out...
Template classes break at compile time, but structures are OK.

Thanks for the message.

It's a rudiment, we'll fix it.

 
TheXpert:

Thanks, didn't think about WinApi access to process memory.

P.s. Personal message is closed, so I'm writing here:
"In reverse engineering, the term hook has a specific meaning - code to intercept the invocation of a function or event."

Reason: