UnsafeArrays.jl icon indicating copy to clipboard operation
UnsafeArrays.jl copied to clipboard

isbitstype vs Base.allocatedinline

Open nielsls opened this issue 1 year ago • 1 comments

UnsafeArrays currently only support types T for isbitstype(T) == true. I suppose the reason for this is that non-bits types are at risk of being GC'ed if their only reference is within an UnsafeArray.

However, this seems overly restrictive as isbitstype returns false for a lot of types (Unions of bitstypes, Ptrs, ..) that are allocated inline and thus not are in risk of being GC'ed. Instead, Base.allocatedinline seems like a better alternative.

E.g.

julia> struct Foo
           x::Union{Int, Nothing}
       end

julia> sizeof(Foo) # 16
16

julia> isbitstype(Foo) # false
false

julia> Base.allocatedinline(Foo) # true
true

julia> isbitstype(Ptr{Int}) # false
true

julia> Base.allocatedinline(Ptr{Int}) # true
true

nielsls avatar Sep 03 '24 19:09 nielsls

Sorry for the late reply!

Using Base.allocatedinline sound interesting, but I think it's an internal Julia function and not part of the public API. Do you know if it's used by other packages?

oschulz avatar Sep 20 '24 12:09 oschulz