Skip to content

Why can’t ref structs be boxed? #107839

Answered by En3Tho
colejohnson66 asked this question in General
Discussion options

You must be logged in to vote

Basically, lifetime safety issues. You can have stack to heap references but not vice versa because it is really easy to shoot yourself in a foot (e.g. stack can be already used for something else or discarded). Depending on your use case you can go unsafe and use pointers to pass ref structs around but you're in your own then.

Another possible thing is that arbitrary heap to heap references might be costly for gc to scan/walk but I'm not sure how much it is.

Replies: 5 comments 6 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by EgorBo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@tagcode
Comment options

@tagcode
Comment options

@SirCxyrtyx
Comment options

@EgorBo
Comment options

@tagcode
Comment options

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