Skip to content

elminate all pointers! #41

@ExpandingMan

Description

@ExpandingMan

I have a major rewrite of this package coming up after which I plan to fully support the arrow standard so we can use it for IPC and all the other cool things all the kids these days are doing.

In the meantime, I just wanted to record here that I should be able to completely eliminate all pointers from this package and have its memory safetcy guaranteed by the memory safety of Julia. Observe!

using BenchmarkTools
       
const N = 128

v = zeros(UInt8, N*sizeof(Int))  

function wrap(::Type{T}, v::AbstractVector, i1::Integer, ℓ::Integer) where {T}
    p = convert(Ptr{T}, pointer(v) + i1)
    w = unsafe_wrap(Array, p, ℓ)  
    copyto!(Vector{T}(undef, ℓ), w)
end

function safe(::Type{T}, v::AbstractVector, i1::Integer, ℓ::Integer) where {T}
    w = reinterpret(T, @view v[i1:(i1 +*sizeof(T) - 1)])
    copyto!(Vector{T}(undef, ℓ), w)    
end
julia> @btime safe(Int, v, 8, 2)
  71.926 ns (3 allocations: 176 bytes)

julia> @btime wrap(Int, v, 8, 2)
  75.115 ns (2 allocations: 176 bytes)

Keno is definitely a badass.

Note that views are now going to be of a really strange type (a reinterpret array of a view). Might have to look into whether Julia needs to add a method for reinterpreting the middle of an array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions