Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-109570

Retire QSharedPointer

    XMLWordPrintable

Details

    • QSharedPointer
    • 100
    • b96b672b2 (dev), 1e3ec1ba2 (dev), b31dfaddd (dev), 3693dd74f (dev)

    Description

      QSharedPointer has several problems. We can either fix them, or phase it slowly out, possibly via a middle step where QSharedPointer becomes a tiny wrapper around shared_ptr, going forward, the way we did in 6.0 with QMap and QPair.

      The main problems are:

      1. a QSP copy up's both strong and weak ref-counts, for a 2x atomic ops load compared to shared_ptr, which only modifies the weak ref-count when the strong one falls to zero. This yields a precise 2x slowdown of QSP vs. shared_ptr (cf. ninja tst_bench_shared_ptr_benchmark)
      2. the unfortunate special mode for QObject payloads, which, among other things, makes it impossible to put a QObject held in QSharedPointer into a QPointer ([[citation needed]])
      3. QSP, unlike std::shared_ptr is not exception-safe
      4. lack of mainenance. shared_ptr has support for arrays and atomic<shared_ptr<>> in C++20, and it's probably not possible for QSharedPointer to do the latter unless it is shared_ptr.
      5. Since Qt 6, the QSharedPointer test suite is no longer complete (negative tests were never ported to cmake (QTBUG-93093))

      This won't be as easy as wrapping the definition into an #ifndef QT_NO_SHARED_POINTER and setting the macro for more and more code until we can define it for all Qt modules and deprecate QSharedPointer.

      The issues in this epic describe some (eventually, all) of the challenges.

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-109570
          # Subject Branch Project Status CR V

          Activity

            People

              cnn Qt Core & Network
              mmutz Marc Mutz
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes