Sign in to follow this  

Confused about move semantics

This topic is 2049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This function was written by a code generator:

[code]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);
}
}

[/code]

My question has to do with the code in the loop. File.hh is [url="http://webEbenezer.net/misc/File.hh"]here[/url] and File.cc is [url="http://webEbenezer.net/misc/File.cc"]here[/url]. (All of the code in question can be downloaded [url="http://webEbenezer.net/misc/direct.tar.bz2"]here[/url].)
If I change the last line in the loop to:
[code] az1.push_back(::std::move(rep2));[/code]

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 2049 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this