Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Confused about move semantics

Reply
Thread Tools

Confused about move semantics

 
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      05-03-2012
I'm still wondering about this

http://www.gamedev.net/topic/624328-...ove-semantics/
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      05-03-2012
On May 3, 7:13*am, (E-Mail Removed) wrote:
> I'm still wondering about this
> http://www.gamedev.net/topic/624328-...ove-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
 
Reply With Quote
 
 
 
 
SG
Guest
Posts: n/a
 
      05-03-2012
On 3 Mai, 16:22, SG wrote:
> On May 3, 7:13*am, (E-Mail Removed) wrote:
>
> > I'm still wondering about this
> >http://www.gamedev.net/topic/624328-...ove-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
 
Reply With Quote
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      05-04-2012
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::BuildPolyInstanc e(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.
 
Reply With Quote
 
woodbrian77@gmail.com
Guest
Posts: n/a
 
      05-05-2012
On Thursday, May 3, 2012 10:19:04 PM UTC-5, (E-Mail Removed) 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::BuildPolyInstanc e(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.)


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Writing move constructors and move assignment Andrew Tomazos C++ 2 12-12-2011 01:45 PM
Move semantics problem. cola C++ 2 10-18-2010 09:54 AM
I am trying to move spaces to a weblistbox and when I move them... Eduardo78 ASP .Net Web Controls 0 11-03-2005 06:06 PM
it's all about semantics =?Utf-8?B?RGltaXRyaXMgUGFudGF6b3BvdWxvcw==?= ASP .Net 2 07-14-2004 08:19 AM
Semantics extractor Luigi Donatello Asero HTML 5 02-14-2004 07:10 PM



Advertisments