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

Ask A Question

Stats

  • Questions 133k
  • Answers 133k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer if( isalnum( buf[ 0 ]) { printf( "%s", buf );… May 12, 2026 at 6:39 am
  • Editorial Team
    Editorial Team added an answer You need a distribution function that takes a number between… May 12, 2026 at 6:39 am
  • Editorial Team
    Editorial Team added an answer Answer from Perforce support: This may be a working and… May 12, 2026 at 6:39 am

Related Questions

One of the cool new features of the upcoming C++ standard, C++0x, are "rvalue
In the current C++0x draft I've noticed they introduced some new explicit keywords to
mmm, I have just a little confusion about multiple auto declarations in the upcoming
Does it matter to developers that the current, and newer versions of .Net don't

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.