Confused about move semantics

S

SG


You changed

for (; headCount[0] > 0; --headCount[0]) {
cmw::File rep2(buf);
az1.push_back(rep2);
}

to

for (; headCount[0] > 0; --headCount[0]) {
cmw::File rep2(buf);
az1.push_back(std::move(rep2));
}

and observed a 492 byte decrease of the executable's size. But the C++
ISO standard does not specify anything related to the size of an
executable or object file as far as I remember. Anyhow, I am surprized
to see this reduction. I would expect to see no change or a slight
increase since a move-version of push_back is instantiated even though
cmw::File has no move constructor (since cmw::File has only a user-
declared copy ctor and no move ctor will be generated implicitly in
this case).

Cheers!
SG
 
S

SG


You changed

    for (; headCount[0] > 0; --headCount[0]) {
        cmw::File rep2(buf);
        az1.push_back(rep2);
    }

to

    for (; headCount[0] > 0; --headCount[0]) {
        cmw::File rep2(buf);
        az1.push_back(std::move(rep2));
    }

and observed a 492 byte decrease of the executable's size. But the C++
ISO standard does not specify anything related to the size of an
executable or object file as far as I remember. Anyhow, I am surprized
to see this reduction. I would expect to see no change or a slight
increase since a move-version of push_back is instantiated even though
cmw::File has no move constructor (since cmw::File has only a user-
declared copy ctor and no move ctor will be generated implicitly in
this case).

Perhaps in all other places you only use the moving push_back
function. Without std::move in this place your executable would
contain both versions of push_back. With std::move in this place your
executable would only contains the moving push_back (because the other
one is never used) and be therefore 492 bytes smaller. It's hard to
tell without knowing all the other code.

SG
 
W

woodbrian77

Perhaps in all other places you only use the moving push_back
function. Without std::move in this place your executable would
contain both versions of push_back. With std::move in this place your
executable would only contains the moving push_back (because the other
one is never used) and be therefore 492 bytes smaller. It's hard to
tell without knowing all the other code.

The code can be downloaded here --
http://webEbenezer.net/misc/direct.tar.bz2 .
The program is my middle tier which I call the cmwAmbassador.
Your theory is interesting, but I'm not sure if it is right.

cmwa_config_data.cc: accounts.push_back(accountInfo);
cmwa_config_data.cc: accounts.push_back(accountInfo);
cmwAmbassador.cc: pendingTransactions.push_back:):std::move(request));
cmw_user_input.cc: headers.push_back( File(static_cast<char const*>(strtok(nullptr, "\n "))) );
MarshallingFunctions.hh: intrlst.push_back(*T::value_type::BuildPolyInstance(buf));
remote_messages_middle.cg.hh: az1.push_back(rep2);

Here are the uses of push_back. I don't think the one in MarshallingFunctions.hh is a factor as it is in a template which isn't instantiated for this program. The last one is the one in the original post.
All but the one in the MarshallingFunctions are used in the program.
Thanks for the idea. I'm still wondering about this.
 
W

woodbrian77

The code can be downloaded here --
http://webEbenezer.net/misc/direct.tar.bz2 .
The program is my middle tier which I call the cmwAmbassador.
Your theory is interesting, but I'm not sure if it is right.

cmwa_config_data.cc: accounts.push_back(accountInfo);
cmwa_config_data.cc: accounts.push_back(accountInfo);
cmwAmbassador.cc: pendingTransactions.push_back:):std::move(request));
cmw_user_input.cc: headers.push_back( File(static_cast<char const*>(strtok(nullptr, "\n "))) );
MarshallingFunctions.hh: intrlst.push_back(*T::value_type::BuildPolyInstance(buf));
remote_messages_middle.cg.hh: az1.push_back(rep2);

I think I misunderstood what you meant about "in all other places"
using the moving push_back function. I thought you meant all
uses of push_back, but now think it is all of the places where
I push_back a File instance. Now I think your theory is probably
right. The only other place where I push_back a File instance is
in cmw_user_input. That is an anonymous use so I think it would
be moved. (Well, this still doesn't explain why either would be
moved when there wasn't supposed to be a move constructor. I've
now added a move constructor to the class.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Confused...? 2
Who invented move semantics? 3
Moles that move 0
Move rules 2
How to move logo up 4
OS X compiler 5
Confused about quotations 5
A question about semantics from the standard library's documentation 2

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top