-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support pointers as memory backend #61
Comments
Actually, that's probably going to work already with #52? |
Currently #52 has the constraint on the Perhaps |
With #52, a good chunk of the work to extend the memory backend to a diff --git a/src/FixedSizeArrays.jl b/src/FixedSizeArrays.jl
index 41c1394..8be5990 100644
--- a/src/FixedSizeArrays.jl
+++ b/src/FixedSizeArrays.jl
@@ -11,10 +11,10 @@ Implementation detail. Do not use.
"""
struct Internal end
-struct FixedSizeArray{T,N,Mem<:GenericMemory{<:Any,T}} <: DenseArray{T,N}
+struct FixedSizeArray{T,N,Mem<:Union{GenericMemory{<:Any,T},Ptr{T}}} <: DenseArray{T,N}
mem::Mem
size::NTuple{N,Int}
- function FixedSizeArray{T,N,M}(::Internal, mem::M, size::NTuple{N,Int}) where {T,N,M<:GenericMemory{<:Any,T}}
+ function FixedSizeArray{T,N,M}(::Internal, mem::M, size::NTuple{N,Int}) where {T,N,M<:Union{GenericMemory{<:Any,T},Ptr{T}}}
new{T,N,M}(mem, size)
end
end
@@ -53,9 +53,19 @@ function FixedSizeArray{T}(::UndefInitializer, size::NTuple{N,Integer}) where {T
FixedSizeArray{T,N}(undef, size)
end
+function FixedSizeArray{T,N}(ptr::Ptr{T}, size::NTuple{N,Integer}) where {T,N}
+ FixedSizeArray{T,N,Ptr{T}}(Internal(), ptr, size)
+end
+function FixedSizeArray{T}(ptr::Ptr{T}, size::NTuple{N,Integer}) where {T,N}
+ FixedSizeArray{T,N}(ptr, size)
+end
+
+
Base.IndexStyle(::Type{<:FixedSizeArray}) = IndexLinear()
Base.@propagate_inbounds Base.getindex(A::FixedSizeArray, i::Int) = A.mem[i]
Base.@propagate_inbounds Base.setindex!(A::FixedSizeArray, v, i::Int) = A.mem[i] = v
+Base.getindex(A::FixedSizeArray{T,N,Ptr{T}}, i::Int) where {T,N} = unsafe_load(A.mem, i)
+Base.setindex!(A::FixedSizeArray{T,N,Ptr{T}}, v, i::Int) where {T,N} = unsafe_store!(A.mem, v, i)
Base.size(a::FixedSizeArray) = a.size At least with this patch you can wrap a pointer into a
|
Today at JuliaCon I was talking with @MasonProtter about this package, and he brought up the idea of making the memory backend type a parameter, so that instead of
Memory{T}
one could use, say,Ptr{T}
.The text was updated successfully, but these errors were encountered: