Confused about move semantics

Discussion in 'C++' started by woodbrian77@gmail.com, May 3, 2012.

  1. Guest

    , May 3, 2012
    #1
    1. Advertising

  2. SG Guest

    On May 3, 7:13 am, wrote:
    > I'm still wondering about this
    > http://www.gamedev.net/topic/624328-confused-about-move-semantics/


    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
     
    SG, May 3, 2012
    #2
    1. Advertising

  3. SG Guest

    On 3 Mai, 16:22, SG wrote:
    > On May 3, 7:13 am, wrote:
    >
    > > I'm still wondering about this
    > >http://www.gamedev.net/topic/624328-confused-about-move-semantics/

    >
    > 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
     
    SG, May 3, 2012
    #3
  4. Guest

    On Thursday, May 3, 2012 11:29:53 AM UTC-5, SG wrote:
    >
    > 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.
     
    , May 4, 2012
    #4
  5. Guest

    On Thursday, May 3, 2012 10:19:04 PM UTC-5, wrote:

    >
    > 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.)
     
    , May 5, 2012
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=

    it's all about semantics

    =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=, Jul 13, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    334
    =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?=
    Jul 14, 2004
  2. cola

    Move semantics problem.

    cola, Oct 15, 2010, in forum: C++
    Replies:
    2
    Views:
    289
  3. Eduardo78
    Replies:
    0
    Views:
    258
    Eduardo78
    Nov 3, 2005
  4. Andrew Tomazos
    Replies:
    2
    Views:
    628
    Nobody
    Dec 12, 2011
  5. Stefan Ram

    Who invented move semantics?

    Stefan Ram, Nov 18, 2013, in forum: C++
    Replies:
    3
    Views:
    149
    W Karas
    Dec 20, 2013
Loading...

Share This Page