# Determine if Array is Mmap?

**URL:** <https://discourse.julialang.org/t/determine-if-array-is-mmap/87354>\
**Category:** General Usage\
**Tags:** question, mmap\
**Created:** [September 16, 2022, 8:26am UTC](https://discourse.julialang.org/t/determine-if-array-is-mmap/87354 "2022-09-16T08:26:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JesperMartinsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jespermartinsson/32/34098_2.png) [@JesperMartinsson](https://discourse.julialang.org/u/JesperMartinsson)\
**Post date:** [September 16, 2022, 8:26am UTC](https://discourse.julialang.org/t/determine-if-array-is-mmap/87354/1 "2022-09-16T08:26:43Z")

</div>

Is there a way to determine if an Array is memory mapped or standard?  
For example, taken from the doc:

```julia
# Create a file for mmapping
# (you could alternatively use mmap to do this step, too)
using Mmap
A = rand(1:20, 5, 30)
s = open("/tmp/mmap.bin", "w+")
# We'll write the dimensions of the array as the first two Ints in the file
write(s, size(A,1))
write(s, size(A,2))
# Now write the data
write(s, A)
close(s)

# Test by reading it back in
s = open("/tmp/mmap.bin") # default is read-only
m = read(s, Int)
n = read(s, Int)
A2 = mmap(s, Matrix{Int}, (m,n))

```

then

```julia
julia> A2
5×30 Matrix{Int64}:
 12 17 4 12 16 18 13 2 12 … 13 7 1 2 7 13 4 15 11
  7 8 13 15 17 12 7 14 18 14 19 15 8 12 4 12 1 4
  5 4 7 4 7 7 18 5 18 4 18 8 3 1 9 13 16 19
 16 19 18 13 10 10 19 20 5 3 18 4 18 11 15 1 7 10
 14 18 15 15 18 17 6 19 16 19 11 15 7 15 10 10 8 9

julia> typeof(A2)
Matrix{Int64} (alias for Array{Int64, 2})

```

but can I by just having `A2` detemine if it is memory mapped or not?

Cheers, Jesper

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [September 16, 2022, 11:22am UTC](https://discourse.julialang.org/t/determine-if-array-is-mmap/87354/2 "2022-09-16T11:22:22Z")

</div>

Didn’t found anything explicitly but you can check if `Mmap.sync!` throws an error:

```julia
function ismmap(a)
	r=true
	try
		Mmap.sync!(a)
	catch e
		r=false
	end
	return r
end

julia> ismmap(A)
false

julia> ismmap(A2)
true

```

But I am not sure if this is always valid.

---

<div class="post-metadata">

**Author:** ![cirobr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cirobr/32/219994_2.png) [@cirobr](https://discourse.julialang.org/u/cirobr)\
**Post date:** [October 3, 2024, 12:47pm UTC](https://discourse.julialang.org/t/determine-if-array-is-mmap/87354/3 "2024-10-03T12:47:22Z")

</div>

Cheers, have just tried the solution with Julia 1.10.5. The A array returns true instead of false… and the documentation looks the same. Any workaround? Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [October 3, 2024, 2:28pm UTC](https://discourse.julialang.org/t/determine-if-array-is-mmap/87354/4 "2024-10-03T14:28:10Z")

</div>

This [very old thread](https://groups.google.com/g/julia-users/c/_OFCVa3HAZQ/m/j0WpevcuHzEJ) is still accurate: we don’t store this information at a high-level and it’s hard to recover at a low level. I don’t think the `Mmap.sync!` error check suggested above was ever reliable.

[https://groups.google.com/g/julia-users/c/\_OFCVa3HAZQ/m/j0WpevcuHzEJ](https://groups.google.com/g/julia-users/c/_OFCVa3HAZQ/m/j0WpevcuHzEJ)

---

<div class="post-metadata">

**Author:** ![JesperMartinsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jespermartinsson/32/34098_2.png) [@JesperMartinsson](https://discourse.julialang.org/u/JesperMartinsson)\
**Post date:** [October 6, 2024, 7:34am UTC](https://discourse.julialang.org/t/determine-if-array-is-mmap/87354/5 "2024-10-06T07:34:23Z")

</div>

Thanks for the interesting link! I didn’t know about this discussion. I decided to wrap it in my own struct to add that possibility, as suggested by Tim in the link.
