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. Fatest way to get available memory on Linux
Forum Updated to NodeBB v4.3 + New Features

Fatest way to get available memory on Linux

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.4k Views
  • 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.
  • B Offline
    B Offline
    bs55
    wrote on last edited by bs55
    #1

    Hi,
    I am developping a video recording program but it sometime exhaust the system's memory.
    I've looked on forums and the simplest solution to get the available memory was this one:

    QProcess qp;
    while (!stopCapture) {
            /* Gets captured image from camera and stores it in a vector */
    
            qp.start("awk", QStringList() << "/MemAvailable/ {print $2}" << "/proc/meminfo");
            qp.waitForFinished();
            QString qs_AvailableMemory = qp.readAllStandardOutput();
            if (qs_AvailableMemory.toLong() / 1024 < 128)
                    break;
    }
    qp.close();
    

    The problem is that this code takes about 10 milliseconds to execute, which causes dropped frames.
    Is there a faster way to get the system's available memory?

    aha_1980A 1 Reply Last reply
    0
    • B bs55

      Hi,
      I am developping a video recording program but it sometime exhaust the system's memory.
      I've looked on forums and the simplest solution to get the available memory was this one:

      QProcess qp;
      while (!stopCapture) {
              /* Gets captured image from camera and stores it in a vector */
      
              qp.start("awk", QStringList() << "/MemAvailable/ {print $2}" << "/proc/meminfo");
              qp.waitForFinished();
              QString qs_AvailableMemory = qp.readAllStandardOutput();
              if (qs_AvailableMemory.toLong() / 1024 < 128)
                      break;
      }
      qp.close();
      

      The problem is that this code takes about 10 milliseconds to execute, which causes dropped frames.
      Is there a faster way to get the system's available memory?

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @bs55

      I guess there might be better ways to achive your final solution video recording (temporary files, e.g.).

      But for your question: a faster way to read /proc/meminfo (which is just a file on a pseuso filesystem) may be using QFile. The fastest way, however would be using API: http://man7.org/linux/man-pages/man2/sysinfo.2.html

      Please note, that both solutions are not portable code (well, sysinfo may work on other Unixes and maybe even on macOS).

      Qt has to stay free or it will die.

      B 1 Reply Last reply
      2
      • aha_1980A aha_1980

        @bs55

        I guess there might be better ways to achive your final solution video recording (temporary files, e.g.).

        But for your question: a faster way to read /proc/meminfo (which is just a file on a pseuso filesystem) may be using QFile. The fastest way, however would be using API: http://man7.org/linux/man-pages/man2/sysinfo.2.html

        Please note, that both solutions are not portable code (well, sysinfo may work on other Unixes and maybe even on macOS).

        B Offline
        B Offline
        bs55
        wrote on last edited by
        #3

        @aha_1980 Thank you for your answer.
        Unfortunatly saving the file is not an option as it takes about 25 ms to save an image so I cannot do it while recording without dropping at least 4 frames...
        Parsing the /proc/meminfo is just slightly faster than using the AWK command but not fast enough.
        I will look into this sysinfo API.

        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