Skip to content
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

isbitstype vs Base.allocatedinline #23

Open
nielsls opened this issue Sep 3, 2024 · 1 comment
Open

isbitstype vs Base.allocatedinline #23

nielsls opened this issue Sep 3, 2024 · 1 comment

Comments

@nielsls
Copy link

nielsls commented Sep 3, 2024

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
@oschulz
Copy link
Collaborator

oschulz commented Sep 20, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants