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. Multiple FIFO queues for QByteArray
Forum Updated to NodeBB v4.3 + New Features

Multiple FIFO queues for QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 5.6k Views 2 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.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by VRonin
    #2

    I did not understand exactly your need but the FIFO container is QQueue

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    McLionM 2 Replies Last reply
    3
    • VRoninV VRonin

      I did not understand exactly your need but the FIFO container is QQueue

      McLionM Offline
      McLionM Offline
      McLion
      wrote on last edited by
      #3

      @VRonin

      Why ever I did look at various other classes but not QQueue ... no clue, must have been blind somehow ... thanks a lot !

      McL

      1 Reply Last reply
      0
      • VRoninV VRonin

        I did not understand exactly your need but the FIFO container is QQueue

        McLionM Offline
        McLionM Offline
        McLion
        wrote on last edited by
        #4

        @VRonin

        Hmmm .. How would I arrange QQueue for a 2-dimensonal storage for 16 queues?

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #5

          std::array< QQueue<MyType> , 16>

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          McLionM 1 Reply Last reply
          0
          • VRoninV VRonin

            std::array< QQueue<MyType> , 16>

            McLionM Offline
            McLionM Offline
            McLion
            wrote on last edited by McLion
            #6

            @VRonin said in [Solved] Multiple FIFO queues for qByteArray:

            std::array< QQueue<MyType> , 16>

            This goes on the stack, right.
            How about the heap?
            Anyhow, I got a warning for upcoming C++ release when including <array>.

            VRoninV 1 Reply Last reply
            0
            • McLionM McLion

              @VRonin said in [Solved] Multiple FIFO queues for qByteArray:

              std::array< QQueue<MyType> , 16>

              This goes on the stack, right.
              How about the heap?
              Anyhow, I got a warning for upcoming C++ release when including <array>.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #7

              QScopedPointer< QQueue<MyType>, QScopedPointerArrayDeleter > myQueue (new QQueue<MyType> [16]);

              @McLion said in [Solved] Multiple FIFO queues for qByteArray:

              Anyhow, I got a warning for upcoming C++ release when including <array>.

              <array> is C++11 standard

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              McLionM 1 Reply Last reply
              1
              • VRoninV VRonin

                QScopedPointer< QQueue<MyType>, QScopedPointerArrayDeleter > myQueue (new QQueue<MyType> [16]);

                @McLion said in [Solved] Multiple FIFO queues for qByteArray:

                Anyhow, I got a warning for upcoming C++ release when including <array>.

                <array> is C++11 standard

                McLionM Offline
                McLionM Offline
                McLion
                wrote on last edited by
                #8

                @VRonin
                Thanks ... never heard about. After 15+ years of plain C I have a lot to learn with Qt / C++.

                This works, I mean at least it compiles:

                QScopedPointer< QQueue<QByteArray>, QScopedPointerArrayDeleter<QQueue<QByteArray> > > myQueue (new QQueue<QByteArray>[16]);
                

                This too:

                myQueue = new QQueue<QByteArray>[16];
                

                Am I correct that - except for the deleting of the object and protection from memory leaks - this ends up in the same?
                Thanks for your great support.

                kshegunovK 1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #9

                  Yes, you are correct, the QScopedPointer does nothing but call delete [] when it goes out of scope

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  1 Reply Last reply
                  0
                  • McLionM McLion

                    @VRonin
                    Thanks ... never heard about. After 15+ years of plain C I have a lot to learn with Qt / C++.

                    This works, I mean at least it compiles:

                    QScopedPointer< QQueue<QByteArray>, QScopedPointerArrayDeleter<QQueue<QByteArray> > > myQueue (new QQueue<QByteArray>[16]);
                    

                    This too:

                    myQueue = new QQueue<QByteArray>[16];
                    

                    Am I correct that - except for the deleting of the object and protection from memory leaks - this ends up in the same?
                    Thanks for your great support.

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #10

                    I'd go the ol' and simple way:

                    typedef QQueue<QByteArray> QByteArrayQueue; // Can be skipped, I just like typedefing
                    QVector<QByteArrayQueue> myQueueVector(16);
                    

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    3
                    • VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #11

                      Has to be noted, however, that both QQueue and QByteArray store the values internally on the heap so there is little gain in using QScopedPointer< QQueue<QByteArray>, QScopedPointerArrayDeleter<QQueue<QByteArray> > > myQueue (new QQueue<QByteArray>[16]); you should allocate a container (in the broad sense, so including QByteArray and QString) on the heap only if you need to manage its life-cycle, there is no risk of stack overflow

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      McLionM 1 Reply Last reply
                      0
                      • VRoninV VRonin

                        Has to be noted, however, that both QQueue and QByteArray store the values internally on the heap so there is little gain in using QScopedPointer< QQueue<QByteArray>, QScopedPointerArrayDeleter<QQueue<QByteArray> > > myQueue (new QQueue<QByteArray>[16]); you should allocate a container (in the broad sense, so including QByteArray and QString) on the heap only if you need to manage its life-cycle, there is no risk of stack overflow

                        McLionM Offline
                        McLionM Offline
                        McLion
                        wrote on last edited by
                        #12

                        @VRonin
                        Thanks for the additional notes.
                        Lifetime does not need to be managed in this case - the object is created/initialized in the main constructor and is used as long as the application is alive.

                        1 Reply Last reply
                        0
                        • VRoninV Offline
                          VRoninV Offline
                          VRonin
                          wrote on last edited by
                          #13

                          In this case I'd declare it as std::array< QQueue<MyType> , 16>

                          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                          ~Napoleon Bonaparte

                          On a crusade to banish setIndexWidget() from the holy land of Qt

                          kshegunovK 1 Reply Last reply
                          0
                          • VRoninV VRonin

                            In this case I'd declare it as std::array< QQueue<MyType> , 16>

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #14

                            @VRonin. I'm dying to hear why std::array (and enforcing c++11) is better than a plain C-style array?

                            Read and abide by the Qt Code of Conduct

                            1 Reply Last reply
                            0
                            • VRoninV Offline
                              VRoninV Offline
                              VRonin
                              wrote on last edited by VRonin
                              #15

                              From Effective Modern C++ by Scott Meyers

                              Of course, as a modern C++ developer, you’d naturally prefer a std::array to a built-in array

                              the 2 main things: bound checks and not losing the size once you pass it to a function. But I think in the end it's just a matter of taste so I would not argue any is better

                              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                              ~Napoleon Bonaparte

                              On a crusade to banish setIndexWidget() from the holy land of Qt

                              kshegunovK 1 Reply Last reply
                              0
                              • VRoninV VRonin

                                From Effective Modern C++ by Scott Meyers

                                Of course, as a modern C++ developer, you’d naturally prefer a std::array to a built-in array

                                the 2 main things: bound checks and not losing the size once you pass it to a function. But I think in the end it's just a matter of taste so I would not argue any is better

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on last edited by kshegunov
                                #16

                                I'd argue against the first, as the compiler puts the stack smashing dummies just to prevent that, as for the second I'd tend to agree. Probably the "best" thing is that you get a bit more type-safety from preventing implicit decay to T * const, but I daresay that's to be weighed against the increased binary size, and c++11 already (almost) throws type-safety out the window with the partial type inferral (i.e. auto).

                                Read and abide by the Qt Code of Conduct

                                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