Reading through the ‘book’, in section 4.1 it begins talking about move semantics, and how it works with memory on the stack vs memory on the heap. Using type String as an example I noticed that there is some minor overhead involved in how strings work. Mostly concerning length and capacity.
So if I were to create a new string. I would have pushed a new string on the stack with the following members:
What this implies to me is that ptr, len, and capacity all live on the stack. So if I were to move that string into a new variable (shallow copy) then would that memory for ptr, len, and capacity still exist on the stack in the original variable and now also the new variable. Basically would I lose the ability to use that memory space in the original variable until it falls out of scope?
So if I were to pass this string into a function with the intent of moving it (not barrow) and not using it any longer, would it still exist in the original function but not be accessible?
I’m just interested because I haven’t seen anyone ask this, but I don’t want to blow up my available stack unknowingly because I didn’t understand what is going on behind the scenes.
Lets not consider optimizations at the moment.