C++11 moves

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

43 Replies - 1071 Views - Last Post: 03 September 2013 - 03:12 PM Rate Topic: -----

#31 jimblumberg  Icon User is online

  • member icon


Reputation: 4069
  • View blog
  • Posts: 12,554
  • Joined: 25-December 09

Re: C++11 moves

Posted 02 September 2013 - 10:49 AM

Quote

I see why is would move after the create, but why not move the existing objects too?

I'm not sure why the copy constructor is being evoked instead of the move copy constructor, but the problem is being caused by the reallocation of the vector. For this small sample you can probably increase the speed by altering the amount of memory reserved for the vector. With my compiler the capacity of the vector increases like:

1
2
4
8
16
32

I find the fastest way to increase the speed of vector operations is to try to avoid as many reallocations as possible.

If you reserve a larger amount then your reallocation will happen much less often.

Jim
Was This Post Helpful? 0
  • +
  • -

#32 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,319
  • Joined: 08-August 08

Re: C++11 moves

Posted 02 September 2013 - 11:00 AM

Yes, I read somewhere that every time the vector needs to reallocate it doubles the size of the allocation in order to limit the average number of copies to 2 per item. I was thinking I might estimate the maximum size of a population over the duration of a run and start with that. Still, it would be nice to get move working throughout. It may be that the STL hasn't fully updated the vector class yet.
Was This Post Helpful? 0
  • +
  • -

#33 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 659
  • View blog
  • Posts: 2,270
  • Joined: 31-December 10

Re: C++11 moves

Posted 02 September 2013 - 11:04 AM

Here's what the output looks like on my machine if you replace the vector::push_back() call in main() with a vector::emplace_back() call:

Quote

push 0
A: 0 0xbfbc0104 created.
A:0x9c30008 moved from 0xbfbc0104
~A (0) 0xbfbc0104
A (0) is here. 0x9c30008
push 1
A: 1 0xbfbc0104 created.
A:0x9c3001c moved from 0xbfbc0104
A:0x9c30018 moved from 0x9c30008
~A (0) 0x9c30008
~A (1) 0xbfbc0104
A (1) is here. 0x9c3001c
push 2
A: 2 0xbfbc0104 created.
A:0x9c30030 moved from 0xbfbc0104
A:0x9c30028 moved from 0x9c30018
A:0x9c3002c moved from 0x9c3001c
~A (0) 0x9c30018
~A (1) 0x9c3001c
~A (2) 0xbfbc0104
A (2) is here. 0x9c30030
push 3
A: 3 0xbfbc0104 created.
A:0x9c30034 moved from 0xbfbc0104
~A (3) 0xbfbc0104
A (3) is here. 0x9c30034
push 4
A: 4 0xbfbc0104 created.
A:0x9c30050 moved from 0xbfbc0104
A:0x9c30040 moved from 0x9c30028
A:0x9c30044 moved from 0x9c3002c
A:0x9c30048 moved from 0x9c30030
A:0x9c3004c moved from 0x9c30034
~A (0) 0x9c30028
~A (1) 0x9c3002c
~A (2) 0x9c30030
~A (3) 0x9c30034
~A (4) 0xbfbc0104
A (4) is here. 0x9c30050
push 5
A: 5 0xbfbc0104 created.
A:0x9c30054 moved from 0xbfbc0104
~A (5) 0xbfbc0104
A (5) is here. 0x9c30054
push 6
A: 6 0xbfbc0104 created.
A:0x9c30058 moved from 0xbfbc0104
~A (6) 0xbfbc0104
A (6) is here. 0x9c30058
push 7
A: 7 0xbfbc0104 created.
A:0x9c3005c moved from 0xbfbc0104
~A (7) 0xbfbc0104
A (7) is here. 0x9c3005c
push 8
A: 8 0xbfbc0104 created.
A:0x9c30088 moved from 0xbfbc0104
A:0x9c30068 moved from 0x9c30040
A:0x9c3006c moved from 0x9c30044
A:0x9c30070 moved from 0x9c30048
A:0x9c30074 moved from 0x9c3004c
A:0x9c30078 moved from 0x9c30050
A:0x9c3007c moved from 0x9c30054
A:0x9c30080 moved from 0x9c30058
A:0x9c30084 moved from 0x9c3005c
~A (0) 0x9c30040
~A (1) 0x9c30044
~A (2) 0x9c30048
~A (3) 0x9c3004c
~A (4) 0x9c30050
~A (5) 0x9c30054
~A (6) 0x9c30058
~A (7) 0x9c3005c
~A (8) 0xbfbc0104
A (8) is here. 0x9c30088
Testing existence of objects:
A (0) is here. 0x9c30068
A (1) is here. 0x9c3006c
A (2) is here. 0x9c30070
A (3) is here. 0x9c30074
A (4) is here. 0x9c30078
A (5) is here. 0x9c3007c
A (6) is here. 0x9c30080
A (7) is here. 0x9c30084
A (8) is here. 0x9c30088
erasing
~A (8) 0x9c30088
Finishing...
~A (0) 0x9c30068
~A (2) 0x9c3006c
~A (3) 0x9c30070
~A (4) 0x9c30074
~A (5) 0x9c30078
~A (6) 0x9c3007c
~A (7) 0x9c30080
~A (8) 0x9c30084

Was This Post Helpful? 1
  • +
  • -

#34 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,319
  • Joined: 08-August 08

Re: C++11 moves

Posted 02 September 2013 - 11:13 AM

You're onto something, but for some reason my code isn't doing it:
#include <iostream>
#include <string>
#include <vector>
#include <utility>

class A
{
public:
	int number;
	
	A(int n) : number(n)
	{
		std::cout << "A: " << number << " " << this << " created." << std::endl;
	}
	
	A(A&& b ) : number(std::move(b.number))
	{
		std::cout << "A:" << this << " moved from " << &b << std::endl;
	}
	
	A(const A & aIn)
	{
		std::cout << "A:" << this << " copied from " << &aIn << std::endl;
		number = aIn.number;
	}
	
	~A()
	{
		std::cout << "~A ("<< number << ") " << this << std::endl;
	}
	
	void Am_I_here()
	{
		std::cout << "A ("<< number << ") is here. " << this << std::endl;
	}
	
	A& operator=(const A&& n)
	{
		number = std::move(n.number);
    std::cout << "A: " << number << " " << this << " MOVED." << std::endl;
    return(*this);
	}
	
	A& operator=(const A& n)
	{
		number = n.number;
		std::cout << "A: " << number << " " << this << " COPY ASSIGNED." << std::endl;
		return(*this);
	}
	
};

int main(int argc, const char * argv[])
{
	std::vector <A> myvector;

	for (size_t i = 0; i < 9; i++) {
		std::cout <<"push "<< i << std::endl;
		myvector.emplace_back(A(i));
		myvector[i].Am_I_here();
	}
	
	std::cout << "Testing existence of objects:"<< std::endl;
	for (size_t i = 0; i < myvector.size(); i++) {
		myvector[i].Am_I_here();
	}
	std::cout << "erasing"<< std::endl;
	
	myvector.erase(myvector.begin()+1);
	
	std::cout << "Finishing..."<< std::endl;
	return 0;
}


results:

Quote

push 0
A: 0 0x7fff5fbff8d8 created.
A:0x1001000e0 moved from 0x7fff5fbff8d8
~A (0) 0x7fff5fbff8d8
A (0) is here. 0x1001000e0
push 1
A: 1 0x7fff5fbff8d8 created.
A:0x100103af4 moved from 0x7fff5fbff8d8
A:0x100103af0 copied from 0x1001000e0
~A (0) 0x1001000e0
~A (1) 0x7fff5fbff8d8
A (1) is here. 0x100103af4
push 2
A: 2 0x7fff5fbff8d8 created.
A:0x1001000e8 moved from 0x7fff5fbff8d8
A:0x1001000e4 copied from 0x100103af4
A:0x1001000e0 copied from 0x100103af0
~A (1) 0x100103af4
~A (0) 0x100103af0
~A (2) 0x7fff5fbff8d8
A (2) is here. 0x1001000e8
push 3
A: 3 0x7fff5fbff8d8 created.
A:0x1001000ec moved from 0x7fff5fbff8d8
~A (3) 0x7fff5fbff8d8
A (3) is here. 0x1001000ec
push 4
A: 4 0x7fff5fbff8d8 created.
A:0x100103b10 moved from 0x7fff5fbff8d8
A:0x100103b0c copied from 0x1001000ec
A:0x100103b08 copied from 0x1001000e8
A:0x100103b04 copied from 0x1001000e4
A:0x100103b00 copied from 0x1001000e0
~A (3) 0x1001000ec
~A (2) 0x1001000e8
~A (1) 0x1001000e4
~A (0) 0x1001000e0
~A (4) 0x7fff5fbff8d8
A (4) is here. 0x100103b10
push 5
A: 5 0x7fff5fbff8d8 created.
A:0x100103b14 moved from 0x7fff5fbff8d8
~A (5) 0x7fff5fbff8d8
A (5) is here. 0x100103b14
push 6
A: 6 0x7fff5fbff8d8 created.
A:0x100103b18 moved from 0x7fff5fbff8d8
~A (6) 0x7fff5fbff8d8
A (6) is here. 0x100103b18
push 7
A: 7 0x7fff5fbff8d8 created.
A:0x100103b1c moved from 0x7fff5fbff8d8
~A (7) 0x7fff5fbff8d8
A (7) is here. 0x100103b1c
push 8
A: 8 0x7fff5fbff8d8 created.
A:0x100103b40 moved from 0x7fff5fbff8d8
A:0x100103b3c copied from 0x100103b1c
A:0x100103b38 copied from 0x100103b18
A:0x100103b34 copied from 0x100103b14
A:0x100103b30 copied from 0x100103b10
A:0x100103b2c copied from 0x100103b0c
A:0x100103b28 copied from 0x100103b08
A:0x100103b24 copied from 0x100103b04
A:0x100103b20 copied from 0x100103b00
~A (7) 0x100103b1c
~A (6) 0x100103b18
~A (5) 0x100103b14
~A (4) 0x100103b10
~A (3) 0x100103b0c
~A (2) 0x100103b08
~A (1) 0x100103b04
~A (0) 0x100103b00
~A (8) 0x7fff5fbff8d8
A (8) is here. 0x100103b40
Testing existence of objects:
A (0) is here. 0x100103b20
A (1) is here. 0x100103b24
A (2) is here. 0x100103b28
A (3) is here. 0x100103b2c
A (4) is here. 0x100103b30
A (5) is here. 0x100103b34
A (6) is here. 0x100103b38
A (7) is here. 0x100103b3c
A (8) is here. 0x100103b40
erasing
A: 2 0x100103b24 MOVED.
A: 3 0x100103b28 MOVED.
A: 4 0x100103b2c MOVED.
A: 5 0x100103b30 MOVED.
A: 6 0x100103b34 MOVED.
A: 7 0x100103b38 MOVED.
A: 8 0x100103b3c MOVED.
~A (8) 0x100103b40
Finishing...
~A (8) 0x100103b3c
~A (7) 0x100103b38
~A (6) 0x100103b34
~A (5) 0x100103b30
~A (4) 0x100103b2c
~A (3) 0x100103b28
~A (2) 0x100103b24
~A (0) 0x100103b20

Was This Post Helpful? 0
  • +
  • -

#35 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 659
  • View blog
  • Posts: 2,270
  • Joined: 31-December 10

Re: C++11 moves

Posted 02 September 2013 - 12:00 PM

What version of clang are you using, because I just tried it with version 3.0-6 and I get this as a result (note that I added some symbols to make the output easier to read):

Quote

*** Pushing 0 ***
=== A: 0 0xbfa021d4 created ===
=== A:0x8dff008 moved from 0xbfa021d4 ===
=== ~A (0) 0xbfa021d4 ===
=== A (0) is here. 0x8dff008 ===
*** Pushing 1 ***
=== A: 1 0xbfa021d4 created ===
=== A:0x8dff01c moved from 0xbfa021d4 ===
=== A:0x8dff018 moved from 0x8dff008 ===
=== ~A (0) 0x8dff008 ===
=== ~A (1) 0xbfa021d4 ===
=== A (1) is here. 0x8dff01c ===
*** Pushing 2 ***
=== A: 2 0xbfa021d4 created ===
=== A:0x8dff030 moved from 0xbfa021d4 ===
=== A:0x8dff028 moved from 0x8dff018 ===
=== A:0x8dff02c moved from 0x8dff01c ===
=== ~A (0) 0x8dff018 ===
=== ~A (1) 0x8dff01c ===
=== ~A (2) 0xbfa021d4 ===
=== A (2) is here. 0x8dff030 ===
*** Pushing 3 ***
=== A: 3 0xbfa021d4 created ===
=== A:0x8dff034 moved from 0xbfa021d4 ===
=== ~A (3) 0xbfa021d4 ===
=== A (3) is here. 0x8dff034 ===
*** Pushing 4 ***
=== A: 4 0xbfa021d4 created ===
=== A:0x8dff050 moved from 0xbfa021d4 ===
=== A:0x8dff040 moved from 0x8dff028 ===
=== A:0x8dff044 moved from 0x8dff02c ===
=== A:0x8dff048 moved from 0x8dff030 ===
=== A:0x8dff04c moved from 0x8dff034 ===
=== ~A (0) 0x8dff028 ===
=== ~A (1) 0x8dff02c ===
=== ~A (2) 0x8dff030 ===
=== ~A (3) 0x8dff034 ===
=== ~A (4) 0xbfa021d4 ===
=== A (4) is here. 0x8dff050 ===
*** Pushing 5 ***
=== A: 5 0xbfa021d4 created ===
=== A:0x8dff054 moved from 0xbfa021d4 ===
=== ~A (5) 0xbfa021d4 ===
=== A (5) is here. 0x8dff054 ===
*** Pushing 6 ***
=== A: 6 0xbfa021d4 created ===
=== A:0x8dff058 moved from 0xbfa021d4 ===
=== ~A (6) 0xbfa021d4 ===
=== A (6) is here. 0x8dff058 ===
*** Pushing 7 ***
=== A: 7 0xbfa021d4 created ===
=== A:0x8dff05c moved from 0xbfa021d4 ===
=== ~A (7) 0xbfa021d4 ===
=== A (7) is here. 0x8dff05c ===
*** Pushing 8 ***
=== A: 8 0xbfa021d4 created ===
=== A:0x8dff088 moved from 0xbfa021d4 ===
=== A:0x8dff068 moved from 0x8dff040 ===
=== A:0x8dff06c moved from 0x8dff044 ===
=== A:0x8dff070 moved from 0x8dff048 ===
=== A:0x8dff074 moved from 0x8dff04c ===
=== A:0x8dff078 moved from 0x8dff050 ===
=== A:0x8dff07c moved from 0x8dff054 ===
=== A:0x8dff080 moved from 0x8dff058 ===
=== A:0x8dff084 moved from 0x8dff05c ===
=== ~A (0) 0x8dff040 ===
=== ~A (1) 0x8dff044 ===
=== ~A (2) 0x8dff048 ===
=== ~A (3) 0x8dff04c ===
=== ~A (4) 0x8dff050 ===
=== ~A (5) 0x8dff054 ===
=== ~A (6) 0x8dff058 ===
=== ~A (7) 0x8dff05c ===
=== ~A (8) 0xbfa021d4 ===
=== A (8) is here. 0x8dff088 ===
*** Testing existence of objects ***
=== A (0) is here. 0x8dff068 ===
=== A (1) is here. 0x8dff06c ===
=== A (2) is here. 0x8dff070 ===
=== A (3) is here. 0x8dff074 ===
=== A (4) is here. 0x8dff078 ===
=== A (5) is here. 0x8dff07c ===
=== A (6) is here. 0x8dff080 ===
=== A (7) is here. 0x8dff084 ===
=== A (8) is here. 0x8dff088 ===
*** Erasing ***
=== ~A (8) 0x8dff088 ===
*** Finishing... ***
=== ~A (0) 0x8dff068 ===
=== ~A (2) 0x8dff06c ===
=== ~A (3) 0x8dff070 ===
=== ~A (4) 0x8dff074 ===
=== ~A (5) 0x8dff078 ===
=== ~A (6) 0x8dff07c ===
=== ~A (7) 0x8dff080 ===
=== ~A (8) 0x8dff084 ===

Was This Post Helpful? 0
  • +
  • -

#36 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,319
  • Joined: 08-August 08

Re: C++11 moves

Posted 02 September 2013 - 12:38 PM

echo | clang -dM -E -
#define __clang__ 1
#define __clang_major__ 4
#define __clang_minor__ 0
#define __clang_patchlevel__ 0
#define __clang_version__ "4.0 ((tags/Apple/clang-421.0.60))"
#define __VERSION__ "4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))"
Is your code the same as mine?

This post has been edited by CTphpnwb: 02 September 2013 - 12:42 PM

Was This Post Helpful? 0
  • +
  • -

#37 vividexstance  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 659
  • View blog
  • Posts: 2,270
  • Joined: 31-December 10

Re: C++11 moves

Posted 02 September 2013 - 12:45 PM

Basically, I just added symbols in the output.
Was This Post Helpful? 0
  • +
  • -

#38 jimblumberg  Icon User is online

  • member icon


Reputation: 4069
  • View blog
  • Posts: 12,554
  • Joined: 25-December 09

Re: C++11 moves

Posted 02 September 2013 - 04:36 PM

Shouldn't that emplace_back() look like:

//        myvector.push_back(A(i));
        myvector.emplace_back(i);



The way I read the documentation you shouldn't need the constructor syntax, it automatically constructs the object using the parameters.

Jim
Was This Post Helpful? 0
  • +
  • -

#39 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,319
  • Joined: 08-August 08

Re: C++11 moves

Posted 02 September 2013 - 05:35 PM

Seems to work either way, but I still get the copied method when expanding the vector.
Was This Post Helpful? 0
  • +
  • -

#40 jimblumberg  Icon User is online

  • member icon


Reputation: 4069
  • View blog
  • Posts: 12,554
  • Joined: 25-December 09

Re: C++11 moves

Posted 02 September 2013 - 06:51 PM

What happens if you comment out the copy constructor?

Jim
Was This Post Helpful? 1
  • +
  • -

#41 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,319
  • Joined: 08-August 08

Re: C++11 moves

Posted 02 September 2013 - 07:23 PM

Then I get this:

Quote

push 0
A: 0 0x1001000e0 created.
A (0) is here. 0x1001000e0
push 1
A: 1 0x100103af4 created.
A:0x100103af0 moved from 0x1001000e0
~A (0) 0x1001000e0
A (1) is here. 0x100103af4
push 2
A: 2 0x1001000e8 created.
A:0x1001000e4 moved from 0x100103af4
A:0x1001000e0 moved from 0x100103af0
~A (1) 0x100103af4
~A (0) 0x100103af0
A (2) is here. 0x1001000e8
push 3
A: 3 0x1001000ec created.
A (3) is here. 0x1001000ec
push 4
A: 4 0x100103b10 created.
A:0x100103b0c moved from 0x1001000ec
A:0x100103b08 moved from 0x1001000e8
A:0x100103b04 moved from 0x1001000e4
A:0x100103b00 moved from 0x1001000e0
~A (3) 0x1001000ec
~A (2) 0x1001000e8
~A (1) 0x1001000e4
~A (0) 0x1001000e0
A (4) is here. 0x100103b10
push 5
A: 5 0x100103b14 created.
A (5) is here. 0x100103b14
push 6
A: 6 0x100103b18 created.
A (6) is here. 0x100103b18
push 7
A: 7 0x100103b1c created.
A (7) is here. 0x100103b1c
push 8
A: 8 0x100103b40 created.
A:0x100103b3c moved from 0x100103b1c
A:0x100103b38 moved from 0x100103b18
A:0x100103b34 moved from 0x100103b14
A:0x100103b30 moved from 0x100103b10
A:0x100103b2c moved from 0x100103b0c
A:0x100103b28 moved from 0x100103b08
A:0x100103b24 moved from 0x100103b04
A:0x100103b20 moved from 0x100103b00
~A (7) 0x100103b1c
~A (6) 0x100103b18
~A (5) 0x100103b14
~A (4) 0x100103b10
~A (3) 0x100103b0c
~A (2) 0x100103b08
~A (1) 0x100103b04
~A (0) 0x100103b00
A (8) is here. 0x100103b40
Testing existence of objects:
A (0) is here. 0x100103b20
A (1) is here. 0x100103b24
A (2) is here. 0x100103b28
A (3) is here. 0x100103b2c
A (4) is here. 0x100103b30
A (5) is here. 0x100103b34
A (6) is here. 0x100103b38
A (7) is here. 0x100103b3c
A (8) is here. 0x100103b40
erasing
A: 2 0x100103b24 MOVED.
A: 3 0x100103b28 MOVED.
A: 4 0x100103b2c MOVED.
A: 5 0x100103b30 MOVED.
A: 6 0x100103b34 MOVED.
A: 7 0x100103b38 MOVED.
A: 8 0x100103b3c MOVED.
~A (8) 0x100103b40
Finishing...
~A (8) 0x100103b3c
~A (7) 0x100103b38
~A (6) 0x100103b34
~A (5) 0x100103b30
~A (4) 0x100103b2c
~A (3) 0x100103b28
~A (2) 0x100103b24
~A (0) 0x100103b20

My current code:
#include <iostream>
#include <string>
#include <vector>
#include <utility>

class A
{
public:
	int number;
	
	A(int n) : number(n)
	{
		std::cout << "A: " << number << " " << this << " created." << std::endl;
	}

	A(A&& b ) : number(std::move(b.number))
	{
		std::cout << "A:" << this << " moved from " << &b << std::endl;
	}

	A& operator=(const A&& n)
	{
		number = std::move(n.number);
    std::cout << "A: " << number << " " << this << " MOVED." << std::endl;
    return(*this);
	}
	
	A& operator=(const A& n)
	{
		number = n.number;
		std::cout << "A: " << number << " " << this << " COPY ASSIGNED." << std::endl;
		return(*this);
	}
	
	/*
	A(const A & aIn)
	{
		std::cout << "A:" << this << " copied from " << &aIn << std::endl;
		number = aIn.number;
	}
	 //*/
	
	~A()
	{
		std::cout << "~A ("<< number << ") " << this << std::endl;
	}
	
	void Am_I_here()
	{
		std::cout << "A ("<< number << ") is here. " << this << std::endl;
	}
	
};

int main(int argc, const char * argv[])
{
	std::vector <A> myvector;

	for (size_t i = 0; i < 9; i++) {
		std::cout <<"push "<< i << std::endl;
		myvector.emplace_back(i);
		myvector[i].Am_I_here();
	}
	
	std::cout << "Testing existence of objects:"<< std::endl;
	for (size_t i = 0; i < myvector.size(); i++) {
		myvector[i].Am_I_here();
	}
	std::cout << "erasing"<< std::endl;
	
	myvector.erase(myvector.begin()+1);
	
	std::cout << "Finishing..."<< std::endl;
	return 0;
}



So that works, but why?

I just noticed that emplace doesn't give me the warning about loss of precision. I doubt that helps, but just in case...
Was This Post Helpful? 0
  • +
  • -

#42 jimblumberg  Icon User is online

  • member icon


Reputation: 4069
  • View blog
  • Posts: 12,554
  • Joined: 25-December 09

Re: C++11 moves

Posted 02 September 2013 - 08:23 PM

Quote

So that works, but why?

Good question, I'm still trying to answer that question myself.

Jim
Was This Post Helpful? 0
  • +
  • -

#43 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1074
  • View blog
  • Posts: 4,533
  • Joined: 09-June 09

Re: C++11 moves

Posted 03 September 2013 - 09:07 AM

Quote

I will need to profile the code, but I'd like to know what is generally faster. I assumed that move would be, but it doesn't seem to be doing a byte by byte copy like I had originally thought, so maybe not.

The answer is, it depends. The purpose of move is, not to do byte by byte copies, but to avoid unecessary memory allocations and copies from temporaries. If your objects does not use any dynamic memory, or STL containers, then a move constructor and copy constructor will usually have the same performance. Move constructors are used to steal pointers away from temporaries.

This post has been edited by jjl: 03 September 2013 - 09:09 AM

Was This Post Helpful? 0
  • +
  • -

#44 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2984
  • Posts: 10,319
  • Joined: 08-August 08

Re: C++11 moves

Posted 03 September 2013 - 03:12 PM

Yes, I was being lazy about that.

I still don't see why on my system it seems to give preference to the copy constructor over the move when both are present and it's increasing the size of a vector.
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3