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. QString bad alloc
Forum Updated to NodeBB v4.3 + New Features

QString bad alloc

Scheduled Pinned Locked Moved Unsolved General and Desktop
14 Posts 6 Posters 1.4k 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.
  • M Offline
    M Offline
    Massimiliano75
    wrote on last edited by
    #5

    the object only lives in the thread, and I use TOP to see the memory status but it is always at 2/3% always low

    1 Reply Last reply
    0
    • kkoehneK Offline
      kkoehneK Offline
      kkoehne
      Moderators
      wrote on last edited by kkoehne
      #6

      do you know if it is a bug fixed in the following qt?

      It's very unlikely that this is a bug in QString itself (or malloc). A typical cause of such errors is heap corruption - that is, in some other code you're accessing memory outside of the allocated bounds, which corrupts the metadata that malloc uses to manage memory.

      These types of issues can be really hard to track down. Anyhow, a tool like valgrind/memcheck can be of help.

      Good luck!

      Director R&D, The Qt Company

      1 Reply Last reply
      4
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #7
        This post is deleted!
        1 Reply Last reply
        0
        • SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by
          #8

          @Massimiliano75 , Can you please show or state the scopes of where your variables are defined?

          For example where is QStringList list; defined and what is its lifetime ?

          M 1 Reply Last reply
          0
          • SPlattenS SPlatten

            @Massimiliano75 , Can you please show or state the scopes of where your variables are defined?

            For example where is QStringList list; defined and what is its lifetime ?

            M Offline
            M Offline
            Massimiliano75
            wrote on last edited by
            #9

            @SPlatten
            for example but line changes
            2022-07-12_11h50_59.png 2022-07-12_11h49_10.png

            1 Reply Last reply
            0
            • SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by
              #10

              @Massimiliano75 , looking at the outer for loop, this will iterate as fast as it can on the hardware it is running on, there are no delays between iterates, each iterates starts by clearing the list then rebuilding it, the list isn't visible to anything else outside of the thread so by do you use a mutex to lock and unlock around appending data to what is an internal list and then only on the second append, I can't see that the mutex is required at all.

              JonBJ 1 Reply Last reply
              0
              • SPlattenS SPlatten

                @Massimiliano75 , looking at the outer for loop, this will iterate as fast as it can on the hardware it is running on, there are no delays between iterates, each iterates starts by clearing the list then rebuilding it, the list isn't visible to anything else outside of the thread so by do you use a mutex to lock and unlock around appending data to what is an internal list and then only on the second append, I can't see that the mutex is required at all.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by JonB
                #11

                @SPlatten
                I think the mutex lock is to protect something in the parameters OP is passing to listBarInfo.append() on that particular line, though not sure what....

                SPlattenS 1 Reply Last reply
                0
                • JonBJ JonB

                  @SPlatten
                  I think the mutex lock is to protect something in the parameters OP is passing to listBarInfo.append() on that particular line, though not sure what....

                  SPlattenS Offline
                  SPlattenS Offline
                  SPlatten
                  wrote on last edited by
                  #12

                  @JonB , then wouldn't it be better to put the mutex locking and unlocking in the access method used?

                  JonBJ 1 Reply Last reply
                  0
                  • SPlattenS SPlatten

                    @JonB , then wouldn't it be better to put the mutex locking and unlocking in the access method used?

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #13

                    @SPlatten
                    Well quite possibly! But we don't know why whatever needs locking, and what it needs locking against. Maybe it only needs locking when called from here? Maybe the thing(s) which need locking do not have access to the mutexModuleData variable which we do here?

                    Certainly it might be clearer/safer to assign such things to local variables in a locked region and then pass those as parameters to whatever is being called, like e.g.:

                    mutexModuleData.lock();
                    auto something = sharedVariable;
                    auto something2 = sharedFunction();
                    listBarInfo.append(something, something2);
                    mutexModuleData.unlock();
                    

                    But this all assumes that is why the OP locked this particular statement and not others. For which we do not have confirmation.

                    SPlattenS 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @SPlatten
                      Well quite possibly! But we don't know why whatever needs locking, and what it needs locking against. Maybe it only needs locking when called from here? Maybe the thing(s) which need locking do not have access to the mutexModuleData variable which we do here?

                      Certainly it might be clearer/safer to assign such things to local variables in a locked region and then pass those as parameters to whatever is being called, like e.g.:

                      mutexModuleData.lock();
                      auto something = sharedVariable;
                      auto something2 = sharedFunction();
                      listBarInfo.append(something, something2);
                      mutexModuleData.unlock();
                      

                      But this all assumes that is why the OP locked this particular statement and not others. For which we do not have confirmation.

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #14

                      @JonB , @Massimiliano75 , I would suggest that moving the mutex management into the access method its the logical and best place for it.

                      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