I’m totally new to reading and writing things in files, so even if I use words like stream or stuff like that when coding, I do not truly understand them (and still not completely interested).
I found a way to write and read convenientely in binary stuff like values and vectors in Python and C++. I recycle them in each program.
I tried seeing in the documentation and an older thread makes use of Serialization.serialize, but when i tried it out it says “stream not defined”.
I just need to let a file open, loop while it’s open and write stuff in each iteration in binary.
Then i close it.
After this i want to read it and put stuff inside an array. To do this i use read! function as pointed out in Reading binary data from a file
However which of these lines do i need to use to write a binary file written with write into a single array?
Or:
If I have integer values at the 1st, 3rd, 4th and 5th position, which I just need as constants, and the real array I want to be filled is the data of floats from the 6th elements on, how can I achieve this?
Is a loop going to remember how much did I read, or do i need to specify somehow what is the last and first bit it needs to read independently the first 5 values and the array from the 6th value?
From what I understand with the following “experiment” the read function advances the position of the pointer by the number of bytes necessary to “express” the type of number (8 bytes for Int64 and the same for Float64).
So 32bytes for 4 integers and 40bytes for 5 floats.
Note that the df array, despite having an Int64 element, is of the Float64 type (I don’t know exactly why, but I think it’s an automatic mechanism that makes the use of the array more efficient. Maybe someone who knows could explain what happens behind the scenes ).
If you used a for loop, I assume, you would have the same kind of behavior as the read function: it reads a value and the position increases by nxbytes (n depends on the type).