Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 237873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:27:38+00:00 2026-05-11T20:27:38+00:00

One of the C++0x improvements that will allow to write more efficient C++ code

  • 0

One of the C++0x improvements that will allow to write more efficient C++ code is the unique_ptr smart pointer (too bad, that it will not allow moving through memmove() like operations: the proposal didn’t make into the draft).

What are other performance improvements in upcoming standard? Take following code for example:

vector<char *> v(10,"astring");
string concat = accumulate(v.begin(),v.end(), string(""));

The code will concatenate all the strings contained in vector v. The problem with this neat piece of code is that accumulate() copies things around, and does not use references. And the string() reallocates each time plus operator is called. The code has therefore poor performance compared to well optimized analogical C code.

Does C++0x provide tools to solve the problem and maybe others?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:27:38+00:00Added an answer on May 11, 2026 at 8:27 pm

    Yes C++ solves the problem through something called move semantics.

    Basically it allows for one object to take on the internal representation of another object if that object is a temporary. Instead of copying every byte in the string via a copy-constructor, for example, you can often just allow the destination string to take on the internal representation of the source string. This is allowed only when the source is an r-value.

    This is done through the introduction of a move constructor. Its a constructor where you know that the src object is a temporary and is going away. Therefore it is acceptable for the destination to take on the internal representation of the src object.

    The same is true for move assignment operators.

    To distinguish a copy constructor from a move constructor, the language has introduced rvalue references. A class defines its move constructor to take an rvalue reference which will only be bound to rvalues (temporaries). So my class would define something along the lines of:

     class CMyString
     {
     private:
         char* rawStr;
     public:
    
         // move constructor bound to rvalues
         CMyString(CMyString&& srcStr) 
         {
             rawStr = srcStr.rawStr
             srcStr.rawStr = NULL;             
         }
    
         // move assignment operator 
         CMyString& operator=(CMyString&& srcStr) 
         {
             if(rawStr != srcStr.rawStr) // protect against self assignment
             {
                 delete[] rawStr;
                 rawStr = srcStr.rawStr
                 srcStr.rawStr = NULL;
             }
             return *this;
         }
    
         ~CMyString()
         {
             delete [] rawStr;
         }
     }
    

    Here is a very good and detailed article on move semantics and the syntax that allows you to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One of my biggest typographical frustrations about HTML is the way that it mangles
One may not always know the Type of an object at compile-time, but may
One of the things that has been talked about a few times on the
One of those classic programming interview questions... You are given two marbles, and told
One of the articles I really enjoyed reading recently was Quality Control by Last.FM
One of my co-workers checked in a some files in SVN and one of
One of the fun parts of multi-cultural programming is number formats. Americans use 10,000.50
One of the joys of working for a government healthcare agency is having to
One thing I've always wanted to do is develop my very own operating system
One of the sites I maintain relies heavily on the use of ViewState (it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.