- #1
MinusTheBear
- 22
- 0
Hey all,
Posting once again. I'm only in my second class on programming ever (with no prior experience to classes). I'm learning about move/copy operations. My textbook says that the move operations is "obviously more efficient than the copy" operation, but it doesn't explain why.
Is it more efficient in the case of deep and shallow copies? The only thing I can really think of is if I had an extremely large array or class object that "stealing" the objects data would be more efficient rather than having two copies of the same object with different memory locations. But at the same time, I don't really see why this is so important because if the array or class object is temporary, it's going to be deleted once it falls out of scope anyway -- so it really just seems like another form of copying to me. I know that the idea is you're moving an r-value to an l-value, but the r-value is temporary, so I don't see why you couldn't just perform a copy with a r-value reference since once the copy is performed, the r-value will fall out of scope and be deleted.
Am I missing something?
Posting once again. I'm only in my second class on programming ever (with no prior experience to classes). I'm learning about move/copy operations. My textbook says that the move operations is "obviously more efficient than the copy" operation, but it doesn't explain why.
Is it more efficient in the case of deep and shallow copies? The only thing I can really think of is if I had an extremely large array or class object that "stealing" the objects data would be more efficient rather than having two copies of the same object with different memory locations. But at the same time, I don't really see why this is so important because if the array or class object is temporary, it's going to be deleted once it falls out of scope anyway -- so it really just seems like another form of copying to me. I know that the idea is you're moving an r-value to an l-value, but the r-value is temporary, so I don't see why you couldn't just perform a copy with a r-value reference since once the copy is performed, the r-value will fall out of scope and be deleted.
Am I missing something?