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

  • SEARCH
  • Home
  • 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 3339302
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:28:35+00:00 2026-05-18T00:28:35+00:00

I have a question about performance of move constructor, pseudo C++ class: typedef tuple<std::string,

  • 0

I have a question about performance of move constructor, pseudo C++ class:

typedef tuple<std::string, std::vector<double>, ...and more...> FooTupleMember;

class Foo1
{
    public:
        Foo1::Foo1 (Foo1&& object) :
            member (std::move (object.member))
        {
            // ...
        }
    private:
        FooTupleMember member;
};

class Foo2
{
    public:
        Foo2::Foo1 (Foo2&& object) :
            member (std::move (object.member))
        {
            // ...
        }
    private:
        std::unique_ptr<FooTupleMember> member;
};

When I move object of Foo1 class it will initialize move constructors of all object stored in tuple right? This mean, that move operation can be quite expensive.

But I move object of Foo2 class whole move operation is much faster because i only pass internal pointer of data stored in smart pointer, right?

R-value reference are faster then l-value reverence, because the require much less copy operations, that’s obvious. However returning object from function using move constructor is still more expensive then storing the same object in smart pointer and returning smart pointer.

Moving objects via l-value is very slow, moving it via smart pointer is very fast and moving it via r-value is somewhere in the middle.

I don’t see “the power” of r-value, because it’s not as effective as many people say. Using smart pointer instead of r-value is IMHO better (I mean faster) and it code elegant and clear. Am I right?

  • 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-18T00:28:36+00:00Added an answer on May 18, 2026 at 12:28 am

    If your class has a lot of members then you have to move all of them (or enough for the move to make sense anyway). This is always going to be more expensive than moving a single (smart) pointer, but is likely less expensive than copying.

    However, storing your data on the heap so you can access it through a pointer (to make move fast) will impact the performance of the rest of your code, since every access must dereference the pointer.

    Profile, and optimize the slow bits. If moving isn’t a bottleneck, then do what makes the rest of your code faster, and vice versa.

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

Sidebar

Related Questions

I have a general question about WPF performance. We have a relatively simple forms
I have a question about Javascript widgets. The widget I am working on simply
I'm just starting to look in to caching to improve performance and have a
I've got a question about reusing table data but a view won't work in
This is my little big question about containers, in particular, arrays. I am writing
Let's say I have a class like so: class Gerbil{ int id; float x,y,z;
This question is about a specific programming problem I am having - I want
jQuery hashchange event For me it looks like most mature solution right now(please correct
Does anyone know of a decent reference for synchronization issues in C++? I'm thinking
I am trying to use LINQ to query a list of objects wherever appropriate.

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.