Skip to content

Commit

Permalink
implement memorymapped array for coord storage
Browse files Browse the repository at this point in the history
  • Loading branch information
axsk committed Sep 23, 2024
1 parent 1de8d5d commit ba834d4
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/mmaped.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Mmap

struct MMapped{S,T,N} <: AbstractArray{T,N} where {S<:AbstractArray{T,N}}
x::S
io::IOStream

MMapped(A::S, io::IOStream) where {T,N,S<:AbstractArray{T,N}} = new{S,T,N}(A, io)
end

function MMapped(A::S, file="/tmp/mmap.bin"::String) where {S}
io = open(file, "w+")
x = Mmap.mmap(io, typeof(A), size(A))
x .= A
MMapped(x, io)
end

Base.size(A::MMapped) = size(A.x)
Base.getindex(A::MMapped, i::Int) = getindex(A.x, i)
Base.getindex(A, I::Vararg) = getindex(A.x, I)
Base.IndexStyle(::MMapped{T}) where {T} = IndexStyle(T)

function lastcat(M::MMapped{S}, y) where {S}
sz = collect(size(M))
sz[end] += size(y)[end]
c = Mmap.mmap(M.io, S, Tuple(sz))
c[length(M.x)+1:end] .= y
return MMapped(c, M.io)
end

0 comments on commit ba834d4

Please sign in to comment.