Array references - page 6

 

For information:

  1. All arrays in MQL5 are passed only by reference (4 or 8 bytes in the stack), so don't be afraid to pass arrays inside functions - no special costs.
  2. It is very dangerous to store real memory references, especially references to arrays controlled by the terminal itself(indicator buffers, OHLC buffers), because they are really changed/reallocated. Moreover, it is impossible to save undocumented references between calls (output and input to the script code) to the EA.
  3. When passing an array to a DLL, the start address of the data block is specified, and the dimensions have to be specified separately.
 
mql5:

The first thing to understand is WHY? And what's the use of it?

You don't want to make links, we will do it ourselves.

And thanks to participants, thanks to posts in this thread I found out, that description in help is outdated...

Yes, it's hilarious ) . But really, I didn't even think it could be published in the help.

Can you tell me about all the flags already then?

Renat:

For information:

  1. All arrays in MQL5 are passed by reference only (4 or 8 bytes in the stack), so don't be afraid to pass arrays inside functions - no special costs.

I'm not afraid, I'm well aware that it's inexpensive. It's just inconvenient.

  1. It is very dangerous to store real memory references, especially references to arrays managed by the terminal itself(indicator buffers, OHLC buffers), because they are really changed/reallocated. All the more, undocumented references between calls (exit and entry into script code) of EA must not be saved.

Please elaborate on this point - can there be memory reallocation during OnCalculate? This is bullshit.

About between calls, of course, it is clear.

I don't want to have a feature that binds an indicator or terminal in general, so I will use the safest variant available.

 
TheXpert:

More on this point please - can there be memory reallocation during OnCalculate? That's just crazy.


Not "during" - between.
 
TheXpert:

More on this point please - can there be memory reallocation during OnCalculate? That's a bummer.

About between calls, of course, it's understandable.

Of course we are talking about possible redistribution between calls.

The problem is that someone will save reference between calls by mistake or explicitly, in 99% of cases everything will work until crash. After that there will be quite expected thoughts "it's Metakvots fault".

For example, we have had such thoughts broadcast by one comrade and have continued to do so for several years now, unable to accept that the history between calls can get swapped/changed.

 
Renat:

Of course, we are talking about possible redistribution between calls.

The problem is that someone is bound to save the link between calls by mistake or explicitly, in 99% of cases everything will work until the crash. After which there will be the expected "It's Metakwots fault" thoughts.

"To fear guilt is not to walk forward" (c).

And one more thing: It is better to regret the done, than the not done.

Renat, let's say I agree that reference variables are a potential source of problems, but this can be said about almost any tool. Sometimes people poke other people with screwdrivers. There is no point in banning screwdrivers now, and it is even more senseless to simply remove them from production, because they can be made at home without too many problems.

"References" as an mql entity is highly desirable, not even in the form of variables, but as a possibility to return a reference ( lvalue ) from function. This will allow to make at least really fast left indexers for containers and give many other additional features, like:

MyTree.Search(Key).GetElement() = NewVal;

And I understand that people will want to return a reference to a local variable from a function!

So, what? Forget about references, because they can make life harder for fools?)

--

Such limitations of mql5 (like lack of links) sometimes strongly motivate "escape to DLL", turning MT5 just into a "market driver" providing connection with broker. But the original idea was just the opposite - to eliminate the need to use external programming tools, because"everything is right here".

 

There is no turning back as we aim for maximum language security.

Working with raw links is a solid and sure step towards a crash. And crashing programs with the entire virtualisation system taken out is not allowed.

Our decision is fully informed. MQL5 is used to write programs that will run on a huge number of computers, and without human involvement.

 

Anyway, I hope the principle is clear to anyone who needs it. I will keep it for now, just to keep it to myself. But she will be, and will be open.

I don't need to explain that references to basic types, like int, are much easier to make without too many problems.

The only issue that causes complexity and implementation issues is the scope of the underlying variable. There's really a wide range of possibilities.

________

Well, and for motivation it is worth noting that links open a whole layer of additional possibilities, like wrappers for example.

 
lvalue links are planned...
 
mql5:
lvalue links are planned...
Man, you should have told me right away) I wouldn't have struggled. But this is great.
 

Greetings all.


I wonder if anything has changed in eight years ?

Or, is it still possible to get an array address from OnCalculate() only using msvcrt.dll and memcpy function?

Or is everyone still "dragging" references to arrays through the entire class structure (alternatively, organizing their own arrays and copying the contents every time) ?

Reason: