Difference between Copy assignment operator vs Move assignment operator

 

Copy Assignment OperatorsMove Assignment Operators
Copy assignment operator takes lvalue reference as an argument.Move assignment operator takes rvalue reference as argument.
Copy assignment operator create a new object from passed object by copying each and every item into a new memory location.Move assignment operator create a new object by using as much memory from passed object.
Since, copy assignment operator use a lot of new memory allocation(for new object). Hence, copy constructors gives bad performance compared to move constructorsSince, move assignment operator use most of memory blocks from passed object. Hence, move constructors gave better performance compared to copy constructors.
Since, copy assignment operator doesn’t make any change to passed object. Hence, passed object can be used after copy operations also.Since, move assignment operator utilizes memory blocks from passed object. Hence, passed object can’t be used after move operations.

For more information related to move assignment operators click here.

Difference between Copy assignment operator vs Move assignment operator Read More

Move Assignment Operator explained with simple example

In C++11 (Introduction to C++11) , move assignment operator are added which can improve any code’s performance drastically. Typically a move assignment operator is same as copy/move constructor but before reusing the memory blocks from passed object, it releases all the memory which is owned by this object. Since, memory reallocation is avoided in case of move assignment operators. Thus it gives better performance.

However while implementing move assignment operators we need to take care of one important point to ensure that the original object can be correctly destroyed.

Let’s take an example to see how this memory reallocation is avoided in case of move assignment.

(more…)

Move Assignment Operator explained with simple example Read More

Introduction to C++11

In August 2011, a new C++ version which is known as C++11 is approved by ISO which adds a lot of new set of features to existing C++ programming language. All official documents related to these changes can be found at ISO C++ committee website.

Why C++11 ?

C++11 significantly improved the core C++ language by making several additions to its standard libraries. Major areas where C++11 is improved from its predecessor includes multithreading support, uniform initialization, generic programming support and performance.

Aims of C++11

  1.  Compatibility and Stability MUST be maintained for old code written in C++98,C++03 and in C.
  2.  Extension of core language preferably be done via standard library.
  3.  System and library design method is preferred compared to introducing new features which is useful only for specific applications.
  4.  Focus to improve type safety by providing safer methods to earlier unsafe methods.
  5.  Improve performance and better interaction with hardware to ensure better,safe and high performance embedded system programming.
  6.  Make C++ easier to teach and learn through increased uniformity, stronger guarantees, and facilities better libraries for beginners. Expert programmers can use other efficient features.
(more…)
Introduction to C++11 Read More