Errors, bugs, questions - page 2745

 
fxsaber:

Optimisation question. In the tester, on every tick I need to get a tick for further work. I do it this way.

It is clear that this variant will be slower:

But SymbolInfoTick is also slower because its string-parameter isn't passed by reference.

Is it possible to have regular SymbolInfo* overloads where string is passed by reference?

It's better to have

In Optimizer, these functions are called tens of billions of times.

Calling Symbol() ALWAYS expands to access global variable _Symbol, as well as Digits(), Point(), Period(), GetLastError(), IsStopped(), UninitializeReason()

 
Ilyas:

The Symbol() call ALWAYS unfolds to access the global variable _Symbol, as do Digits(), Point(), Period(), GetLastError(), IsStopped(), UninitializeReason()

And passing of string by reference?

 
fxsaber:

And passing a string by reference?

Apparently the reason is one of the unsolvable problems in MQL - passing a literal as a parameter by const ref.

 
fxsaber:

Is it possible to have regular SymbolInfo* overloads, where string is passed by reference?

How would they help?

int SymbolInfoTick( string  symbol ) { return 1; }
int SymbolInfoTick( string& symbol ) { return 2; }
void OnStart()
{
        Print( SymbolInfoTick( _Symbol ));
}

It still returns 1, not 2

 
fxsaber:

And passing a string by reference?

The string is passed by reference.

We have long ago moved to "copy_on_write string" -> when copying one string to another content is not copied immediately (as it was before), the number of references to string buffer is increased
For example, the number of references is increased when passing string by value, as a parameter and is reduced after the call.
When

a string is changed, the buffer reference count is checked and if there is more than one reference, the string to be changed is "unlinked" from the old buffer and a new one is allocated.

 
A100:

How will they help?

It still returns (called) 1, not 2

The _Symbol variable is constant
 
Ilyas:
The _Symbol variable is constant

Then overloading won't help, either.

int SymbolInfoTick(       string  ) { return 1; }
int SymbolInfoTick( const string& ) { return 2; }
void OnStart()
{
        Print( SymbolInfoTick( _Symbol )); //Error
}

there will be an error already at compile time

 
Ilyas:

The string is passed by reference.

We have long ago moved to "copy_on_write string" -> when copying one string to another the content is not copied immediately (as it was before), the number of references to the string buffer is increased
For example, the number of references is increased when the string is passed by value, as a parameter and decreased after the call.
When

a string is changed, the buffer reference count is checked and if there is more than one reference, the changed string is "unlinked" from the old buffer and a new one is allocated to it.

Is this all defined at compile level?

 

Compiler error:

class CArray
{  
};

int ArraySize(const CArray&);


void Main()
{
  CArray arr;
  ArraySize(arr);  // Нормально
  
  CArray arrays[1];
  ArraySize(arrays[0]); // 'arrays' - array required
}
 
fxsaber:

Is this all defined at compile level?

No. It is not yet known at compile time.