Writing to the file on a new line - page 3

 
Alexey Viktorov:

And the concept is only for you on the surface.........

I meant that the suggestion (concept) "to experiment on your own" does not need to be voiced, it is clear as it is. Igor I perfectly understood and myself thought about this option, for the reason that it is the simplest, but to me imho it is not very suitable, for the circumstances described above.

 
EfremovSergey:

Here's the catch: there are 10 programs that write to the file and another 10 that read from it, you don't want each reading program to process all the accumulated data for all time.

And in this case, it's better to abandon the file altogether and work with a SQLite database. This is very similar to working with files, you can also create in a shared folder, but the processing, searching and deleting the string is much easier.

 

Sergey, if you don't need to look at this file with your eyes, then write an array of your data into it at once

int eHandle=FileOpen(eFileName,FILE_BIN|FILE_WRITE);
if(eHandle!=INVALID_HANDLE)
   {
   //сначала записываем размер массива
   FileWriteInteger(eHandle,ArraySize(eArray),INT_VALUE);
   //выгружаем данные из массива в файл
   FileWriteArray(eHandle,eArray,0,WHOLE_ARRAY);
   FileClose(eHandle);
   }

then take the array out of the file at any time

if(FileIsExist(eFileName))
   {
   eHandle=FileOpen(eFileName,FILE_BIN|FILE_READ);
   if(eHandle!=INVALID_HANDLE)
      {
      //сначала читаем и устанавливаем размер массива
      ArrayResize(eArray,FileReadInteger(eHandle,INT_VALUE));
      //затем выгружаем данные из файла в массив
      FileReadArray(eHandle,eArray,0,WHOLE_ARRAY);
      FileClose(eHandle);
      }
   }

And work with the array as you wish. Delete the last element, add more.

 
Alexey Viktorov:

And in this case, it is better to abandon the file altogether and work with a SQLite database. This is very similar to working with files, you can also create in a shared folder, but processing, searching and deleting rows is much easier.

Does MQL4 support working with SQLite? Isn't it just TXT and CSV format?

Access to the file is done through a symbolic link, it does not matter where the file lies, in which folder.

 
Aleksei Stepanenko:

Sergey, if you don't need to look at this file with your eyes, then write an array of your data into it at once

then take the array out of the file at any time

And work with the array as you wish. Delete the last element, add another.

So, what's the difference, the array is written to the file line by line in any case, or in this case, it is possible to remove at least the last or first element, array=string?

 

I don't quite understand the question. You have an array of data on which you can do any kind of manipulation with ease. And a simple write and read from the file in four lines of code. That's the advantage. Why think about how an array is written to a file?

You make the necessary changes in the array, upload the modified array to a file, and that's it.

 
Aleksei Stepanenko:

I don't quite understand the question. You have an array of data on which you can do any kind of manipulation with ease. And a simple write and read from the file in four lines of code. That's the advantage. Why think about how an array is written to a file?

You make the necessary changes in the array, upload the modified array to a file and that's it.

The difficulty here is that 20 applications will have to handle one and the same array at a time, and it is impossible to determine which particular edited version of the array is relevant at the current moment.

Suppose the first Expert Advisor has edited an array and published it, and another version of the array was written over it, without taking into account the previous one, and that's it... confusion...

If for example every Expert Advisor could delete the related line after it has been read, then everything would work out - no one disturbs anybody and the file will not be overloaded with redundant data, but every time the edited array is written in a race, then it's unclear how to synchronize the actuality of data from each of the 20 Expert Advisors.

 

Managing multiple EAs' access to the same file is something you need to think about.

Here is something for you to think about:

1. To prevent two EAs from working on the same file at the same time, create another flag file. When this file doesn't exist, the Expert Advisor has the right to open the file with the data, before that create a file-flag, showing the others that it is busy so far. After reading-writing, the EA deletes the file-flag. The data is now free for any other EA to work on.

2. You can make variables to collect information about any Expert Advisor that has used the data in this array. Write these variables in the same file.

3. Instead of the usual array, create an array of structures, which includes different types of data and is very visual.

struct MyData
   {
   int EANumber;
   datetime writeTime;
   double mydata1;
   double mydata2;
   } mydata[];
 
Aleksei Stepanenko:

The management of multiple EAs accessing the same file is something you need to think about.


When several Expert Advisors need to write+add+select+read one dataset, then databases are involved willy-nilly.

You can use"global variables" and flags, but why the hell not?

That's a DBMS thing. Different, relational, NoSQL and others, but it's theirs. And there in their mechanics everything is fine-tuned for years and decades. All locs-flags-semaphores-mutexes.
Trying to replicate it is a wild waste of time.

 
Exactly!