[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
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
- 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?
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?
If you set count too high, you get a lot of null values (right?)
The documentation seems to say
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?
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.
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):
I use (writing and reading are two independent steps):
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.
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.