Array references

 

Motive:

The point is that quite often in turkeys you need access to timeseries, which are passed to OnCalculate.

The nesting of these functions can be quite significant, and we have to drag this array from OnCalculate throughout the call chain as a parameter.

While in a significant part of the chain this array isn't needed in the hell.

What we want:

Some semblance of an array reference, like this:

class TimeReference
{
//
   datetime Time[];
};

TimeReference TimeRef;

datetime F()
{
   return TimeRef.Time[0];
}

int OnCalculate(const int bars,
                const int counted,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& sprd[])
{
   TimeRef.Assign(time);
   F();
}

BUT. Mandatory condition - there should be no array copying.

At first glance, this may seem unrealizable. But I suspect it can be done.

What do you think, gentlemen?

 

It's a piece of memory. MQL doesn't explicitly point to memory.

But you can get it with memcpy. it returns what you need.

Then you can drag that value wherever you want. and use memcpy for the same way.

check out my article on DLLs

 
sergeev:
How do I slip this pointer back in?
 
The same memcpy, which is where the pointer is passed to.
 
sergeev:
with memcpy. That's where the pointer is passed to.

No, they can take the pointer but not the slip.

___________

Okay, so it's probably impossible to do it properly.

 
TheXpert:
No, they can take the pointer but not slip it.

and slip it in, tested.

 
sergeev:

and slip it in, tested.

Give me an example.
 
TheXpert:
Show me an example.

Well, it's in the article, isn't it?

I'm trying to insert the code. The server freezes.

 
sergeev:

Well, it's in the article, isn't it?

It's not in the article. There is only memory copying from an array to a pre-prepared array.
 
https://www.mql5.com/ru/articles/364#3

first example

int Source is passed - essentially a memory address

and copied into the array char Dest[10]

Избавляемся от балласта самодельных DLL
Избавляемся от балласта самодельных DLL
  • 2012.01.31
  • o_O
  • www.mql5.com
Если MQL5-программисту недостаточно функционала языка, он вынужден обращаться к дополнительным инструментам. Для этого приходится использовать другой язык программирования и создавать промежуточную DLL. В MQL5 имеется механизм представления разных типов данных с помощью структур и передачи их в API, но к сожалению, MQL5 не отвечает нам на вопрос о том, как вытянуть данные из принятого указателя. В данной статье мы поставим точку в этом вопросе и покажем простые механизмы обмена сложными типами данных и работе с ними.
 

did you get it right? are you overloading memcpy for all types now?

Just don't forget that address size is long for 64 bits.

--------------

Suggestion number one: do you think we should ask developers to make a native function like long ArrayGetAddress( object array) ?

If they won't do it, suggestion two: we should push #ifdef. Renat promised to implement it.

Reason: