-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[Question] how to return stack allocated bytes without putting it in the heap? #62127
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
The stack is "method scoped", so it's gone when the method (i.e. the scope) is left. That's how stack works.
* could use fixed sized buffers or by specifing the size of the struct to be 256 |
Yes, the short answer is "you can't". However, there is talk of adding a method that is specifically designed for such a purpose: #52065
|
@Joe4evr The method proposed there violates the "you can't return stack-allocated bytes" principle, but I don't think it will let you violate it yourself, so it wouldn't be useful here. |
the api looks nice, right n I am just passing in span/, that's already allocated in stack to the function I am calling, it would be nice if I can just get it from the function I am calling though and I get the method to return int or a struct or something but it's not very convenient when the size of the bytes I am returning is changing but I have a way around it too by using a fixed size buffer and another byte that tells me how many bytes actually returned so basically I am getting a frame back from the function, since I am beating to bush for around 1~16 bytes I should be fine |
I am pretty sure it's just 256 bytes maximum while the usual case being 7 bytes.
I would like to return them in the manner like I would return a int.
The text was updated successfully, but these errors were encountered: