According to https://doc.rust-lang.org/stable/rust-by-example/std/box.html,
All values in Rust are stack allocated by default. Values can be boxed (allocated on the heap) by creating a Box. A box is a smart pointer to a heap allocated value of type T. When a box goes out of scope, its destructor is called, the inner object is destroyed, and the memory on the heap is freed.
So if I have a std::vec::Vec<MyStruct>
and I add a lot of structs, does this mean that the structs are stack allocated? How can this be possible? I can only have a collection of things if they're on the heap. Things on the stack are made in compile time, since I understand.
Vec
for instance stores its internal data on the heap. – Dulguun Otgon