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. Get available physical memory, multiple plattforms?

Get available physical memory, multiple plattforms?

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

    Hello!

    I hope, I am in the correct (sub-)forum.
    I´d like to know, if I can get the available physical memory at runtime. I highly suppose, that such a function would be plattform-dependent.
    As I´m using Qt, it would be great, if there was a wrapper-function in Qt, that calls these functions for the corresponding plattform.
    If not: I`d need such a function for Windows, Linux and Mac.

    I already googled for hours and often found the statement, that the need for such a function is a hint for errors in programming/ design. That´s why I want to explain my background:

    I´ve got several files containing tons of data, which needs to be combined (the i-th line of each file has to be combined). As I don´t want to read line 1 from file 1, skip to file 2, read line 1 there and go on skipping files, until I can combine the data from the first line of all files, I want to read several lines in each file and combine the corresponding data afterwards to save I/O-costs.
    But it does not make sense to read all lines and to put these directly to the swap-file, as the physical memory is full. That´s why I want to read those files block-wise. To determine the perfect blocksize, it is necessary to know the available physical memory.
    If I have any error in reasoning, I appreciate your comments, of course ;)

    Thanks!

    Maria

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      AFAIK, there is no platform independent way to get this information. Getting it should not be hard though. However, the amount of installed physical memory tells you little or nothing about the amount of memory that may be available for your application, unless your application runs in a very controlled environment. That will hinder your plans, I think. I understand where you're coming from, but I don't think there is a perfect solution.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dangelog
        wrote on last edited by
        #3

        Notice that (almost) nothing prevents the OS from forcibly swapping out pages. But yes, go with platform-specific code. Under Linux all you need is parsing the /proc/meminfo file.

        Software Engineer
        KDAB (UK) Ltd., a KDAB Group company

        1 Reply Last reply
        0
        • J Offline
          J Offline
          justMe
          wrote on last edited by
          #4

          Thanks to both of you for your fast replys.
          I know, that I cannot prevent it and I cannot know, what other applications use.
          Nethertheless, I hope, that I´ll find a usefull percentage of the available physical memory, assuming, that the user of my application is aware of the fact, that he should not run other heavy applications at the same time.
          Additionally, a swap would just slow the execution down (as long as the virtual memory is not fully loaded as well), so it would be no drama (just not nice).

          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