Jump to content

  • Log In with Google      Sign In   
  • Create Account


Confused about move semantics


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 wood_brian   Banned   -  Reputation: 197

Like
0Likes
Like

Posted 01 May 2012 - 08:59 PM

This function was written by a code generator:

template <typename R>
void
Receive (::cmw::ReceiveBufferTCPCompressed<R>& buf
		 , ::std::vector<cmw::File>& az1
		)
{
  uint32_t headCount[1];
  buf.Give(headCount[0]);
  az1.reserve(az1.size() + headCount[0]);
  for (; headCount[0] > 0; --headCount[0]) {
	cmw::File rep2(buf);
	az1.push_back(rep2);  
  }
}


My question has to do with the code in the loop. File.hh is here and File.cc is here. (All of the code in question can be downloaded here.)
If I change the last line in the loop to:
az1.push_back(::std::move(rep2));

the size of the executable is reduced by 492 bytes. I thought that since File has a user defined copy constructor and destructor, the compiler wouldn't generate a move constructor for the class. I figured the compiler would ignore the std::move call and use the copy constructor and the two versions would produce the same size executables. What am I missing? Thanks.

Edit: The compiler is g++ 4.8 released a few days ago -- April 29th.
(I'm also wondering how to build just g++ when I download a gcc snapshot. It builds a bunch of Fortran and Java stuff that I'm not interested in.)

Edited by wood_brian, 02 May 2012 - 01:46 AM.


Sponsor:

#2 wood_brian   Banned   -  Reputation: 197

Like
0Likes
Like

Posted 05 May 2012 - 03:01 PM

Someone on another newsgroup gave what seems to be a helpful explanation:

https://groups.google.com/forum/?fromgroups#!topic/comp.lang.c++/uVu6LEYO0pQ

#3 Adam_42   Crossbones+   -  Reputation: 2437

Like
0Likes
Like

Posted 05 May 2012 - 04:57 PM

You might want to compare the linker map files from the two versions. In my experience that usually tells you where size differences come from, as long as you can decipher the symbol names.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS