Planned maintenance: From Sunday 8th December 10:00 CET there will be changes to try and solve the caching issues that have been experienced. If anyone has a problem connecting after this period then please PM @AndyS or any of the moderators.
Get available physical memory, multiple plattforms?
justMe last edited by
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 ;)
andre last edited by
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.
dangelog last edited by
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.
justMe last edited by
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).