# Trouble using Mmap

**URL:** <https://discourse.julialang.org/t/trouble-using-mmap/125924>\
**Category:** General Usage\
**Tags:** mmap\
**Created:** [February 14, 2025, 9:38pm UTC](https://discourse.julialang.org/t/trouble-using-mmap/125924 "2025-02-14T21:38:06Z")\
**Posts on this page:** 6\
**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 14, 2025, 9:38pm UTC](https://discourse.julialang.org/t/trouble-using-mmap/125924/1 "2025-02-14T21:38:06Z")

</div>

Hi, I’m exploring the use of mmap and getting the error below when mmap is called  
The line is:  
countIndex = mmap(“tmp”, Matrix{UInt32}, (NUM\_BIGRAMS,30); shared=false)

I’ve also tried a file handle as produced by ‘open’ instead of “tmp” and with/without the offset argument. Here’s the error:

ERROR: MethodError: no method matching unsafe\_wrap(::Type{Array}, ::Ptr{UInt32}, ::Tuple{UInt32, Int64})  
The function `unsafe_wrap` exists, but no method is defined for this combination of argument types.

Closest candidates are:  
unsafe\_wrap(::Union{Type{Array}, Type{Array{T}}, Type{Array{T, N}}}, ::Ptr{T}, ::NTuple{N, Int64}; own) where {T, N}  
@ Base pointer.jl:108  
unsafe\_wrap(::Union{Type{Array}, Type{Array{T}}, Type{Vector{T}}}, ::Ptr{T}, ::Integer; own) where T  
@ Base pointer.jl:113  
unsafe\_wrap(::Union{Type{Array}, Type{Array{T}}, Type{Array{T, N}}, Type{GenericMemory{kind, \<:Any, Core.AddrSpace{Core}(0x00)}}, Type{GenericMemory{kind, T, Core.AddrSpace{Core}(0x00)}}} where kind, ::Ptr{T}, ::NTuple{N, var"#s123"} where var"#s123"\<:Integer; own) where {T, N}  
@ Base pointer.jl:129  
…  
Would anyone have any suggestions?

---

<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 14, 2025, 10:16pm UTC](https://discourse.julialang.org/t/trouble-using-mmap/125924/2 "2025-02-14T22:16:53Z")

</div>

Can you provide a stack trace? The line as written seems correct (many lines of 0x00000000 truncated):

```julia
julia> using Mmap

julia> countindex = mmap("tmp", Matrix{UInt32}, (1000, 3); shared=false)
1000×3 Matrix{UInt32}:
 0x00000000 0x00000000 0x00000000
...

```

---

<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 14, 2025, 10:26pm UTC](https://discourse.julialang.org/t/trouble-using-mmap/125924/3 "2025-02-14T22:26:37Z")

</div>

Here it is:  
Stacktrace:  
[1] mmap(io::IOStream, ::Type{Matrix{UInt32}}, dims::Tuple{UInt32, Int64}, offset::Int64; grow::Bool, shared::Bool)  
@ Mmap ~/.julia/juliaup/julia-1.11.3+0.x64.apple.darwin14/share/julia/stdlib/v1.11/Mmap/src/Mmap.jl:260  
[2] mmap  
@ ~/.julia/juliaup/julia-1.11.3+0.x64.apple.darwin14/share/julia/stdlib/v1.11/Mmap/src/Mmap.jl:188 [inlined]  
[3] #7  
@ ~/.julia/juliaup/julia-1.11.3+0.x64.apple.darwin14/share/julia/stdlib/v1.11/Mmap/src/Mmap.jl:277 [inlined]  
[4] open(::Mmap.var"#7#8"{Matrix{UInt32}, Bool, Bool, Tuple{UInt32, Int64}, Int64}, ::String, ::Vararg{String}; kwargs::@Kwargs{})  
@ Base ./io.jl:410  
[5] open  
@ ./io.jl:407 [inlined]  
[6] mmap  
@ ~/.julia/juliaup/julia-1.11.3+0.x64.apple.darwin14/share/julia/stdlib/v1.11/Mmap/src/Mmap.jl:273 [inlined]  
[7] top-level scope  
@ none:1

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [February 14, 2025, 10:41pm UTC](https://discourse.julialang.org/t/trouble-using-mmap/125924/4 "2025-02-14T22:41:05Z")

</div>

`NUM_BIGRAMS` doesn’t match `30` in type, but the `dims` for `mmap` requires a Tuple of the same type of integer, which the docs are vague about. Watch out that other functions often more strictly require `dims` with all `Int`.

---

<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 14, 2025, 10:42pm UTC](https://discourse.julialang.org/t/trouble-using-mmap/125924/5 "2025-02-14T22:42:19Z")

</div>

Ah, it looks like `NUM_BIGRAMS` is a UInt32 and 30 is a UInt64, they need to both be Int64. Try

```
countIndex = mmap(“tmp”, Matrix{UInt32}, (Int64(NUM_BIGRAMS),30); shared=false)

```

---

<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 14, 2025, 11:00pm UTC](https://discourse.julialang.org/t/trouble-using-mmap/125924/6 "2025-02-14T23:00:07Z")

</div>

Thank you!!
