Errors, bugs, questions - page 2724

 
Slava :

No. FileFlush must be done if you want someone else to be able to read the modified file

The problem is that the MQL5 program reads the file into its own buffer when opening it. And it doesn't know anything about anything having changed in the file until it reads the file again. The file can only be read again by closing and then opening that file

Glory, that's the problem exactly. Please have a look at the link I post above, you will find the code to reproduce it.

The same file opens from the same EA, 1 descriptor for writing, 2nd for reading, fileflush is used after writing, try reading, and it doesn't work correctly.

Of course, if you close/open it works, but then there is no need to use FileFlush.

 
Alain Verleyen:

Glory, this is the problem exactly. Please have a look at the link I publish above, you will find the code to reproduce it.

The same file opens from the same advisor, 1 descriptor for writing, 2nd for reading, fileflush is used after writing, try reading, and it doesn't work correctly.

Of course if you close/open it works, but then there is no need to use FileFlush.

I understand the problem you describe.

The 1st EA writes the file. It may not close that file, but in that case it should call FileFlush

The 2nd Expert Advisor reads the file. It should open the file each time, then close it.

Open and close the file for the second EA only!

 
Slava:

That's exactly what I'm talking about. Close, then reopen

Or do you mean FileFlush before closing the file?

Yes, is it necessary to flush before closing? Or does closing it guarantee the relevance of the recorded file.

 
Andrey Barinov :

Yes, is it necessary to flush before closing? Or does closing ensure that the recorded file is up-to-date.

Flushing is useless if you close immediately afterwards.
 
Slava :

I understand the problem you describe.

The 1st EA writes the file. It may not close the file, but in this case it should call FileFlush

The 2nd Expert Advisor reads the file. It has to open the file each time, then close it.

Opening and closing the file only for the second EA!

I understand that this is a workaround.

But it would be better to correct the mistake, it's not possible easily, I suppose?

 
Andrey Barinov:

Yes, is it necessary to flush before closing? Or does closing ensure that the recorded file is up-to-date.

Not necessarily. Buffers are reset automatically if no FileFlush call was made before closing

 

Bug MT5 (build 2390) incorrectly counts curly braces in class structure description.

class A{};
class B : public A};  // Ok

class C : public A   

void OnStart()
{
   A a;
}                      // Compile Error: '}' - unexpected end of program        
 
Slava:

An Expert Advisor that reads a file must keep this file closed.

The peculiarity of files implementation in MQL5 is that they keep data from files in their own buffers as much as possible. If the size of the information is so large that it doesn't fit into the buffer, your trick with moving the pointer to the beginning and then to the end of the file may work.

So at the moment open file, check contents, then close again

As I told above (in your own text), it's vice versa in my test-case - indicator reads, Expert Advisor writes. But as far as I understand, the type of program is not important. The problem is architectural.

The specified file implementation in MQL5 is a bug. Closing and opening a file is a workaround, but it shouldn't be like this for reading a shared file.

Taking care of performance optimisation is good, but it should not negatively affect the functionality.

PS. As a quick&dirty fix, here's a suggestion: in response to a FileFlush call for a file open for reading - update its buffer.

 
Vict:

Probably because µl C++ is similar, and structures came there from C.

If you need constructors, use classes or welcome to Sharp. Why should you deprive structures of this connotation? This will only make programs more expressive. I may take somebody's code and see that he/she has a structure instead of a class and get a lot of information from just one word. You will get nothing, you will diligently study the source code to get the same result, which I got in a blink of an eye. In my experience - this convention of structures is respected, well, maybe some kind of wind nihilistic marginalism.

But in C++ structures and classes are one and the same thing. That's why all your reasoning about "code expressiveness" doesn't affect the essence of things.You may as well define any other expressive word except struct or class through a define and it won't change anything (I mean C++).

That is why we should speak about structures only from C# point of view. That is where their concept is taken from. Structures are value types, so they are much more compact than classes, they are not polymorphic, and they cannot be referenced. The latter is especially important.

There's no evil there, it seems to you. There's even a standard extended: reading uninitialized unsigned char and std::byte is not undefinded behavior. You can use aggregate initialization for POD. And do not forget - all this initialization is not free, it's real resource consumption (CPU, memory, size of an executable). If you don't give a shit about it with your number cruncher, in case of some microcontroller it may be important. After all, C/C++ is not just a Windows form factor like Sharp.

Initialising one variable alone increased instruction size by 30%.

Nobody says that initialization is free by itself, but one would need it anyway, so I don't really understand the meaning of your measurements with and without initialization.

Another thing is that the compiler won't re-initialize variables:

int a= 0;  // Эту инициализацию компилятор вырежет
//...
a= 10;

So all this paranoia about being afraid of variable pre-initialization is ridiculous. This is 2020, especially if you speak about POD-structures. Their initialization is sure to be optimized by the compiler.

The absence of pre-initialization is acceptable only when there is 100% compiler control prohibiting reading of uninitialized variables.

 
Alexey Navoykov:

In C++, structures and classes are one and the same thing. So all your arguments about "code expressiveness" do not affect the essence of things.You may as well define any other expressive word but struct or class through a define and it won't change (I mean C++)

What a stubborn person ))), it's the same thing for you, you don't need to define anything by a define, there is already a word - struct. You can ignore it, but then don't be surprised that decent coders will look at you as a shit-coder when they see your structures stuffed with functions. Perhaps it was a mistake at the dawn of crosses to equate structures and classes, you should have left structures as in C.

That's why we should speak about structures only from the point of view of C#. That is where their concept is taken from. Structures are value-types, so they are much more compact than classes, are not polymorphic, and cannot be referenced. This last is especially important.

Do you think your Sharp appeared in a clean field? Rooted in C, the structure is a dumb container with no extra sugar.

Another thing is that the compiler won't re-initialize variables:

int a= 0;  // Эту инициализацию компилятор вырежет
//...
a= 10;

So all this paranoia about being afraid of variable pre-initialization is ridiculous. This is 2020, especially if you're talking about POD structures. Their initialization is sure to be optimized by the compiler.

How can you be so sure? Calling a function from another translation unit/another module/cycles/the compiler is out of tune/... . Don't overestimate the capabilities of the optimizer. This is not Copy elision optimization that compilers are obliged to do. If optimizers get so smart and it stops costing anything, they will write in the next C standard: "default initialization does not leave an object in undefined state".
Reason: