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. Time critical execution and QThread

Time critical execution and QThread

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

    Hello,

    I have an app that is time critical (adjusting hardware to be able to track things on a conveyor belt with 1mm/ms). So im working with a lot of raw pointers to keep memory allocated and swap the contents in and out.

    3 questions:

    • Do QSharedPointer and QScopedPointer generate any overhead for allocating the memory?
    • Is it possible to assign a certain heap space to a thread so for long running-systems I can minimize the fragmentation to keep up with performance?

    What are other options that I have to make my code and calculations execute fast. Neglecting hardware limitations for now.

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

      The important thing to have in mind is the cache. It sounds like you have a vector of pointers. One problem with this is that when you iterate of the vector you won't necessarily access adjacent memory. This will totally screw with cache performance. Even if you were to get a huge slice of memory for your thread this slice would still be internally fragmented. On the other hand, if you were to use a regular vector of objects (instead of pointers) it will screw with you real time requirement. Occasionally, you'll have a resize of the vector which will copy all of its data which will slow it down. Only if you can make sure there is no resize happening (as you said you are swapping things out) this could work. Otherwise you need to find some middle ground: something like chunks of memory linked together such that each chunk with several objects/values fits into a cache line (maybe the size of a L2 cache line).

      And finally, the most important advice: Use profiling to measure where your performance bottleneck is to optimize in areas where it is actually necessary and helpful.

      1 Reply Last reply
      3
      • R Redman

        Hello,

        I have an app that is time critical (adjusting hardware to be able to track things on a conveyor belt with 1mm/ms). So im working with a lot of raw pointers to keep memory allocated and swap the contents in and out.

        3 questions:

        • Do QSharedPointer and QScopedPointer generate any overhead for allocating the memory?
        • Is it possible to assign a certain heap space to a thread so for long running-systems I can minimize the fragmentation to keep up with performance?

        What are other options that I have to make my code and calculations execute fast. Neglecting hardware limitations for now.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #2

        @Redman said in Time critical execution and QThread:

        QSharedPointer and QScopedPointer

        They do not allocate memory they only make sure that memory is freed when not referenced any-more or when going out of scope. There is not much overhead.

        You can always allocate a big chunk of heap memory and use it. You can also use placement new to allocate memory in that chunk (https://stackoverflow.com/questions/222557/what-uses-are-there-for-placement-new).

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        R 1 Reply Last reply
        2
        • jsulmJ jsulm

          @Redman said in Time critical execution and QThread:

          QSharedPointer and QScopedPointer

          They do not allocate memory they only make sure that memory is freed when not referenced any-more or when going out of scope. There is not much overhead.

          You can always allocate a big chunk of heap memory and use it. You can also use placement new to allocate memory in that chunk (https://stackoverflow.com/questions/222557/what-uses-are-there-for-placement-new).

          R Offline
          R Offline
          Redman
          wrote on last edited by
          #3

          @jsulm Exactly what I've been looking for. Thank you very much!

          1 Reply Last reply
          1
          • R Redman has marked this topic as solved on
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #4

            The important thing to have in mind is the cache. It sounds like you have a vector of pointers. One problem with this is that when you iterate of the vector you won't necessarily access adjacent memory. This will totally screw with cache performance. Even if you were to get a huge slice of memory for your thread this slice would still be internally fragmented. On the other hand, if you were to use a regular vector of objects (instead of pointers) it will screw with you real time requirement. Occasionally, you'll have a resize of the vector which will copy all of its data which will slow it down. Only if you can make sure there is no resize happening (as you said you are swapping things out) this could work. Otherwise you need to find some middle ground: something like chunks of memory linked together such that each chunk with several objects/values fits into a cache line (maybe the size of a L2 cache line).

            And finally, the most important advice: Use profiling to measure where your performance bottleneck is to optimize in areas where it is actually necessary and helpful.

            1 Reply Last reply
            3
            • R Redman has marked this topic as unsolved on
            • R Redman has marked this topic as solved on

            • Login

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