Trouble using Mmap

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?

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

julia> using Mmap

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

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

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.

1 Like

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)

Thank you!!