3 ms·
In Rust you can allocate small structs on the stack while being confident that the plain pointer passed down the stack will be valid throughout the function exe
by kubb 4y ago
In Rust you can allocate small structs on the stack while being confident that the plain pointer passed down the stack will be valid throughout the function execution.
In C++, you need to use a plain pointer or a unique pointer. The former makes the function leak when passed a pointer to heap.
The latter requires a heap allocation and free for the struct contents.
- menaerus 4y agoYou probably want to revisit your understanding because what you said doesn't make much sense. Allocating variables on stack and passing them over to other functions is perfectly fine. If you want them to live on a heap that's perfectly fine too.