I’m trying to understand how to use memory mapping. Here’s a bit of code that represents what I’d like to do. I want to write to an array, and have the changes propagated to a file. Is that not how Mmap works? The code below leaves the file “mmap-test.bin” unchanged.
using Mmap
s = open("/tmp/mmap-test.bin","w+") # default is read-only
A = mmap(s, Matrix{Int}, (5,30); grow=true)
A[1,1]=10
Mmap.sync!(A)
close(s)
How are you testing that the file is changed? After running the code you provided,
/tmp$ xxd mmap-test.bin | head -n 1
00000000: 0a00 0000 0000 0000 0000 0000 0000 0000 ................
I see a 10 there at the start. And re-running the code after changing the assigned value to 20 results in
/tmp$ xxd mmap-test.bin | head -n 1
00000000: 1400 0000 0000 0000 0000 0000 0000 0000 ................
As expected.
Ah, I was trying to use hexdump but I was unfamiliar with how to read the output. ‘xxd’ seems much easier. Thanks!