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. sharing/copying a Qbytearray

sharing/copying a Qbytearray

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.0k 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.
  • A Offline
    A Offline
    alex_qwa
    wrote on last edited by
    #1

    Hello every one .
    I receive some data over a socket and store it in a local QBytearray (located on the stack).

    QBytearray rxMsg;
    

    The rcvd data will pass over a few functions while being processed. I want to avoid un-necessary copying in this process.
    1- I think passing this data as a refernece would cause me problems

    void onProcessMsg(QBytearray& data)
    

    (because the rxMsg is on the local stack of the first function that would be destroyed upon returning). Is my understanding right?

    2- should I use smart pointers or using QBytearray itself would suffice (The Qbytearray documentation mentions about "implicit sharing"; which i dont fully grasp)
    Thanks in advance.

    Venkatesh VV 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @alex_qwa

      Hi
      http://doc.qt.io/qt-5/implicit-sharing.html

      Anyway, if the functions calls are in same scope then its ok with reference.
      void main_func() {
      QBytearray rxMsg;
      func_call(rxMsg)
      func_call2(rxMsg)

      } // rxMsg killed by scope

      but why not just make it member of the class ? then it lives as long as class.

      A 1 Reply Last reply
      5
      • A alex_qwa

        Hello every one .
        I receive some data over a socket and store it in a local QBytearray (located on the stack).

        QBytearray rxMsg;
        

        The rcvd data will pass over a few functions while being processed. I want to avoid un-necessary copying in this process.
        1- I think passing this data as a refernece would cause me problems

        void onProcessMsg(QBytearray& data)
        

        (because the rxMsg is on the local stack of the first function that would be destroyed upon returning). Is my understanding right?

        2- should I use smart pointers or using QBytearray itself would suffice (The Qbytearray documentation mentions about "implicit sharing"; which i dont fully grasp)
        Thanks in advance.

        Venkatesh VV Offline
        Venkatesh VV Offline
        Venkatesh V
        wrote on last edited by
        #3

        @alex_qwa

        Hi,

        As mrjj said, make that as member variable of a class so that there will be no confusion around the data.

        1 Reply Last reply
        1
        • mrjjM mrjj

          @alex_qwa

          Hi
          http://doc.qt.io/qt-5/implicit-sharing.html

          Anyway, if the functions calls are in same scope then its ok with reference.
          void main_func() {
          QBytearray rxMsg;
          func_call(rxMsg)
          func_call2(rxMsg)

          } // rxMsg killed by scope

          but why not just make it member of the class ? then it lives as long as class.

          A Offline
          A Offline
          alex_qwa
          wrote on last edited by
          #4

          @mrjj thanks a lot (the link was also very usefull)

          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