Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. C++11 QString pass by reference?
Forum Updated to NodeBB v4.3 + New Features

C++11 QString pass by reference?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 6.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wooyay
    wrote on last edited by
    #1

    Hi all,
    I am starting a Qt5 project where I want to use C++11 exclusively.
    Which is faster for QStrings now, pass by value or pass by reference?

    Cheers,
    Martin

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      QString is implicitly shared, so it's quite fast either way. You can benchmark if you prefer, I guess passing by reference would be a little bit faster, but probably not that much.

      (Z(:^

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Here's an article for more details: http://qt-project.org/doc/qt-5.0/qtcore/implicit-sharing.html

        As sierdzio said, there's probably no noticeable difference between passing by value or passing by reference, because QString is very highly optimized already

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stereomatching
          wrote on last edited by
          #4

          I always pass by reference because of two reasons

          1 : pass by reference don't need to take the price of reference count
          2 : it is more natural since the stl containers do not ask to use reference count technique,
          many c++ programmers may feel weird when they see you pass by value rather than pass by reference.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved