# Does Mmap.sync! from disk to array, array to disk, or both?

**URL:** https://discourse.julialang.org/t/does-mmap-sync-from-disk-to-array-array-to-disk-or-both/126012
**Category:** General Usage
**Tags:** mmap
**Created:** [February 17, 2025, 11:18pm UTC](https://discourse.julialang.org/t/does-mmap-sync-from-disk-to-array-array-to-disk-or-both/126012 "2025-02-17T23:18:22Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ilanggear](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ilanggear/32/862_2.png) [@ilanggear](https://discourse.julialang.org/u/ilanggear)
#### Post date: [February 17, 2025, 11:18pm UTC](https://discourse.julialang.org/t/does-mmap-sync-from-disk-to-array-array-to-disk-or-both/126012/1 "2025-02-17T23:18:22Z")

</div>

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)

```

---

<div class="post-metadata">

### Author: ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)
#### Post date: [February 17, 2025, 11:29pm UTC](https://discourse.julialang.org/t/does-mmap-sync-from-disk-to-array-array-to-disk-or-both/126012/2 "2025-02-17T23:29:37Z")

</div>

How are you testing that the file is changed? After running the code you provided,

```julia
/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

```julia
/tmp$ xxd mmap-test.bin | head -n 1
00000000: 1400 0000 0000 0000 0000 0000 0000 0000 ................

```

As expected.

---

<div class="post-metadata">

### Author: ![ilanggear](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ilanggear/32/862_2.png) [@ilanggear](https://discourse.julialang.org/u/ilanggear)
#### Post date: [February 17, 2025, 11:37pm UTC](https://discourse.julialang.org/t/does-mmap-sync-from-disk-to-array-array-to-disk-or-both/126012/3 "2025-02-17T23:37:30Z")

</div>

Ah, I was trying to use hexdump but I was unfamiliar with how to read the output. ‘xxd’ seems much easier. Thanks!
