Why there is a need of move constructor or move semantics in C++? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Why there is a need of move constructor or move semantics in C++?

Why creator thinks that move constructor is powerful than implementing copy constructor or copy assignment operator function?

17th Jan 2020, 1:23 PM
Amit chavare
Amit chavare - avatar
1 Resposta
+ 1
Look at it as an optimization. The copy generates data duplication and memory reservation. If the original object is going to be unnecessary (because after the operation is ruined), the movement builder is faster because you move pointers instead of data. In the assignment you modify the object instead of using an existing one but you must clean the internal memory before moving pointers Miralo como una optimizaciĆ³n. La copia genera duplicaciĆ³n de datos y reserva de memoria. Si el objeto original va a ser imnecesario ( pues luego de la operaciĆ³n se arruina), el constructor de movimiento es mas rĆ”pido pues mueves punteros en lugar de datos. En la asignaciĆ³n modificas el objeto en lugar de usar uno ya existente pero debes limpiar la memoria interna antes de mover punteros
24th Jan 2020, 11:20 PM
Master Forts šŸ‡¦šŸ‡·
Master Forts šŸ‡¦šŸ‡· - avatar