[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 311

 
chief2000:

- Is it possible to find out the number of elements of an array in a file? How to avoid unnecessary actions in this case in general?


FileSize(handle) divided by element size = number of elements?
 
Figar0:

FileSize(handle) divided by item size = number of items?

Is this an assumption?

How do you know the size of an item in a binary file? Maybe some part of it is occupied by more than just elements?

 
chief2000:

If you set count too high, you get a lot of null values (right?)

The documentation seems to say

Функция возвращает количество фактически прочитанных элементов.
 
chief2000:

Is this an assumption?

How do you know the size of an item in a binary file? Perhaps some part of it is occupied by more than just the elements?


The size of an item depends on what you are writing there, either 4 or 8. What does your writing process look like?
 
Roger:

The documentation seems to say

If a file has 1000 elements and count=20, it will actually read 20.

But what happens if count=5000?

It's not clear what they mean by "Before reading data the array must be of sufficient size" - it would be easier to read all elements into the array by number of elements, and then if necessary you can truncate the array, etc.

 
Figar0:

The size of the item depends on what you are writing there, either 4 or 8. What does your writing process look like?

I use (writing and reading are two independent steps):

 FileWriteArray( int handle, object array[], int start, int count) 
 
chief2000:

I use (writing and reading are two independent steps):


int FileWriteArray( int handle, object array[], int start, int count)

The function writes the array to a binary file. Arrays like int, bool, datetime and color are written as 4-byte integers. Arrays of type double are written as floating point numbers. 8-byte floating point numbers.

I have outlined what you need to know. If an array of doubles was written to the file, then dividing the file size by 8 will give you the number of array elements in the file.

 
Figar0:

int FileWriteArray( int handle, object array[], int start, int count)

The function writes the array to a binary file. Arrays like int, bool, datetime and color are written element by element as 4-byte integers. Arrays of type double are written as floating point numbers. 8-byte floating point numbers.

I have highlighted what you need to know. If an array double was written to a file, then dividing the file size by 8 will give you the number of array elements in the file.

Now opened one saved file in a text viewer - this is what it looks like:

It looks like it has about 50 elements (there should be about that many elements), but its size is 2432 bytes. Apparently it stores "blanks" in it.

 
Hello all. Please advise. How can I use MQL4 in an indicator in a separate window to draw the histogram not from zero, but from specified values. I want the Ishimoku indicator to draw the values for other timeframes in a separate window.
 
chief2000: Apparently, it stores the "blank" in it.
It stores what you put in it) There are no miracles.
Reason: