I've put the code, stripped to a minimal example here:
You can see that the single write + read version of the code works just fine:
pageData[0..4] = [1, 2, 3, 4]
readData[0..4] = [1, 2, 3, 4]
Where here, pageData
is the data to be written to a file, and readData
is the result of trying to read the freshly written file data.
But if the same code is placed inside of a for
loop, suddenly no writes occur:
pageData[0..4] = [0, 0, 0, 0]
readData[0..4] = [0, 0, 0, 0]
pageData[0..4] = [0, 0, 0, 1]
readData[0..4] = [0, 0, 0, 0]
pageData[0..4] = [0, 0, 0, 2]
readData[0..4] = [0, 0, 0, 0]
pageData[0..4] = [0, 0, 0, 3]
readData[0..4] = [0, 0, 0, 0]
pageData[0..4] = [0, 0, 0, 4]
readData[0..4] = [0, 0, 0, 0]
// ...
Does anyone know what is happening here? It's really puzzling.