4 ms·
> you can easily create e.g. a `&str` out of a `String` or a `&[T]` out of a `Vec<T>`. I think what op means is both `&str` and `&[T]` live on the stack, even
by kaoD 9y ago
> you can easily create e.g. a `&str` out of a `String` or a `&[T]` out of a `Vec<T>`.
I think what op means is both `&str` and `&[T]` live on the stack, even if they reference slices of heap-allocated (or static) data.
- dbaupp 9y agoThe String and Vec objects live on the stack in the same way, but they contain pointers to heap data. I think the grandparent was trying to get at the fact that &str etc don't force things onto the heap nor do they keep things on the heap alive.
- saghm 9y agoYep, from looking at all the comments in response in my original comment, it seems like I didn't do a great job explaining what I meant here; the basic idea is that if I'm trying to optimize my program by minimizing heap allocations, I can safely ignore any instances of &str, &[T], etc. and just focus on String, Vec, etc.