Are there other types that are always on the heap? It turns out there are!! Here they are:
Vec (an array on the heap)
String (a string on the heap)
That sounds wrong to me. Both Vec<T> and String—as far as I know—are triples: a length (usize), a capacity (usize), and a pointer into the heap. Those three values can be stored in the stack, however the pointer will always point to a memory block in the heap.
That sounds wrong to me. Both
Vec<T>andString—as far as I know—are triples: a length (usize), a capacity (usize), and a pointer into the heap. Those three values can be stored in the stack, however the pointer will always point to a memory block in the heap.Yes, you’re correct here; the author is being a bit less precise than you. It’s how many people think about it most of the time, though.