According to the Rust documentation:
Vectors always allocate their data on the heap.
As I understand this, it means that:
- Rust will allocate enough memory on the heap to store the type
T
in a contiguous fashion. - Rust will not individually box the items as they are placed into the vector.
In other words, if I add a few integers to a vector, while the Vec
will allocate enough storage to store those integers, it's not also going to box those integers; introducing another layer of indirection.
I'm not sure how I can illustrate or confirm this with code examples but any help is appreciated.