@@ -3,13 +3,13 @@ module PtrArrays
3
3
export malloc, free, PtrArray
4
4
5
5
"""
6
- PtrArray(ptr::Ptr{T}, dims::Int...; check_dims=true) <: AbstractArray {T}
6
+ PtrArray(ptr::Ptr{T}, dims::Int...; check_dims=true) <: DenseArray {T}
7
7
8
- Wrap a pointer in an `AbstractArray ` interface conformant `PtrArray` using the standard
8
+ Wrap a pointer in an `DenseArray ` interface conformant `PtrArray` using the standard
9
9
Julia memory order.
10
10
11
11
Validates that `dims` are non-negative and don't overflow when multiplied if `check_dims` is
12
- true. Wierd things might happen if you set `check_dims=false` and use nagative or
12
+ true. Weird things might happen if you set `check_dims=false` and use negative or
13
13
overflowing `dims`.
14
14
15
15
!!! note
@@ -20,7 +20,7 @@ overflowing `dims`.
20
20
21
21
see also [`malloc`](@ref), [`free`](@ref)
22
22
"""
23
- struct PtrArray{T, N} <: AbstractArray {T, N}
23
+ struct PtrArray{T, N} <: DenseArray {T, N}
24
24
ptr:: Ptr{T}
25
25
size:: NTuple{N, Int}
26
26
function PtrArray (ptr:: Ptr{T} , dims:: Vararg{Int, N} ; check_dims= true ) where {T, N}
71
71
Free the memory allocated by a [`PtrArray`](@ref) allocated by [`malloc`](@ref).
72
72
73
73
It is only safe to call this function on `PtrArray`s returned by `malloc`, and it is unsafe
74
- to perform any opperation on a `PtrArray` after calling `free`.
74
+ to perform any operation on a `PtrArray` after calling `free`.
75
75
"""
76
76
free (p:: PtrArray ) = Libc. free (p. ptr)
77
77
@@ -87,4 +87,8 @@ Base.@propagate_inbounds function Base.setindex!(p::PtrArray, v, i::Int)
87
87
p
88
88
end
89
89
90
+ # Strided array interface https://docs.julialang.org/en/v1/manual/interfaces/#man-interface-strided-arrays
91
+ Base. unsafe_convert (:: Type{Ptr{T}} , p:: PtrArray{T} ) where T = p. ptr
92
+ Base. elsize (:: Type{P} ) where P<: PtrArray = sizeof (eltype (P))
93
+
90
94
end
0 commit comments