Skip to content
Browse files

Name the constructor something besides Array, and build into sysimg.

  • Loading branch information...
1 parent 8329784 commit d65e897caa6fd2aefea5768b4e6b106eab7eb6c9 @timholy committed Apr 22, 2012
Showing with 13 additions and 12 deletions.
  1. +11 −11 base/mmaparray.jl
  2. +2 −1 base/sysimg.jl
View
22 base/mmaparray.jl
@@ -1,13 +1,6 @@
-function munmap(p,len)
- ret = ccall(:munmap,Int,(Ptr{Void},Int),p,len)
- if ret != 0
- error(strerror())
- end
-end
-
# Bare-bones mmapped-array constructor
# This is needed for fancy stuff, such as MAP_ANONYMOUS.
-function Array{T,N}(::Type{T}, dims::NTuple{N,Int}, prot::Int, flags::Int, fd::Integer, offset::FileOffset)
+function mmap_array{T,N}(::Type{T}, dims::NTuple{N,Int}, prot::Int, flags::Int, fd::Integer, offset::FileOffset)
const pagesize::Int = 4096
offset_page::FileOffset = ifloor(offset/pagesize)*pagesize
len::Int = prod(dims)*sizeof(T) + offset - offset_page
@@ -22,7 +15,7 @@ function Array{T,N}(::Type{T}, dims::NTuple{N,Int}, prot::Int, flags::Int, fd::I
end
# More user-friendly mmapped-array constructor
-function Array{T,N}(::Type{T}, dims::NTuple{N,Int}, s::IOStream, offset::FileOffset)
+function mmap_array{T,N}(::Type{T}, dims::NTuple{N,Int}, s::IOStream, offset::FileOffset)
const PROT_READ::Int = 1
const PROT_WRITE::Int = 2
const MAP_SHARED::Int = 1
@@ -38,7 +31,14 @@ function Array{T,N}(::Type{T}, dims::NTuple{N,Int}, s::IOStream, offset::FileOff
prot = PROT_READ | PROT_WRITE
end
flags = MAP_SHARED
- A = Array(T, dims, prot, flags, fd(s), offset)
+ A = mmap_array(T, dims, prot, flags, fd(s), offset)
return A
end
-Array{T,N}(::Type{T}, dims::NTuple{N,Int}, s::IOStream) = Array(T, dims, s, position(s))
+mmap_array{T,N}(::Type{T}, dims::NTuple{N,Int}, s::IOStream) = mmap_array(T, dims, s, position(s))
+
+function munmap(p::Ptr,len::Int)
+ ret = ccall(:munmap,Int,(Ptr{Void},Int),p,len)
+ if ret != 0
+ error(strerror())
+ end
+end
View
3 base/sysimg.jl
@@ -74,8 +74,9 @@ include("statistics.jl")
# random number generation
include("random.jl")
-# distributed arrays
+# distributed arrays and memory-mapped arrays
include("darray.jl")
+include("mmaparray.jl")
# utilities - version, timing, help, edit
include("version.jl")

0 comments on commit d65e897

Please sign in to comment.
Something went wrong with that request. Please try again.