C++ reading out memory specs [modified]
-
Hy folks, I have a little question of reading out the amount of memory that one can use for a program. I know there exists the method filling up the memory until you get an exception, but this isn't a nice way, right? So my question: Is there a way to read out memory specs in windows and other platforms as well? I was just wondering if one of you can thing of a nice platform independent function or approach to calculate the amount of memory available in the system. Also I am interested to find out the amount of processors to calculate the amount of threads for that platform. I am sorry for the leaking of knowledge. :sigh: Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
modified on Tuesday, March 24, 2009 11:41 AM
-
Hy folks, I have a little question of reading out the amount of memory that one can use for a program. I know there exists the method filling up the memory until you get an exception, but this isn't a nice way, right? So my question: Is there a way to read out memory specs in windows and other platforms as well? I was just wondering if one of you can thing of a nice platform independent function or approach to calculate the amount of memory available in the system. Also I am interested to find out the amount of processors to calculate the amount of threads for that platform. I am sorry for the leaking of knowledge. :sigh: Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
modified on Tuesday, March 24, 2009 11:41 AM
Check out
GlobalMemoryStatusEx()
and the structureMEMORYSTATUSEX
on MSDN. -
Check out
GlobalMemoryStatusEx()
and the structureMEMORYSTATUSEX
on MSDN.Thanks. But this is just for windows, right? Or do you thing I have to check the op system before doing something. If that is possible. I am also interested in reading out the sys specs in general. For example the amount of processors to calculate how many threads I could start.. But thanks for pointing me in a direction. Cheers.
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
-
Thanks. But this is just for windows, right? Or do you thing I have to check the op system before doing something. If that is possible. I am also interested in reading out the sys specs in general. For example the amount of processors to calculate how many threads I could start.. But thanks for pointing me in a direction. Cheers.
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
Yes, only for Windows (unless you use something like Wine on Linux). There are articles about system info in this section: http://www.codeproject.com/KB/system/[^]
-
Yes, only for Windows (unless you use something like Wine on Linux). There are articles about system info in this section: http://www.codeproject.com/KB/system/[^]
Thanks you very much. But still either I am blind or just not seeing it, I can not find a nice function or a set of functions that return me system information. Actually, if I am allow to keep you busy, I am lacking of knowledge to detecting on which op I am on. I mean if I can detect what Os I am facing, it is straight forward to use your suggestion for windows and in Linux, I think, the specs are written in a file. Macs fights for their owns. :) But thanks for the great answers. Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
-
Thanks you very much. But still either I am blind or just not seeing it, I can not find a nice function or a set of functions that return me system information. Actually, if I am allow to keep you busy, I am lacking of knowledge to detecting on which op I am on. I mean if I can detect what Os I am facing, it is straight forward to use your suggestion for windows and in Linux, I think, the specs are written in a file. Macs fights for their owns. :) But thanks for the great answers. Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
Fatbuddha 1 wrote:
But still either I am blind or just not seeing it, I can not find a nice function or a set of functions that return me system information.
Well, you have to read the articles and look at the code.
Fatbuddha 1 wrote:
I am lacking of knowledge to detecting on which op I am on.
Do you mean which version of the OS? Like Win XP, 2000 etc.? Or Linux, MacOS, Windows?
-
Thanks you very much. But still either I am blind or just not seeing it, I can not find a nice function or a set of functions that return me system information. Actually, if I am allow to keep you busy, I am lacking of knowledge to detecting on which op I am on. I mean if I can detect what Os I am facing, it is straight forward to use your suggestion for windows and in Linux, I think, the specs are written in a file. Macs fights for their owns. :) But thanks for the great answers. Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
Fatbuddha 1 wrote:
I mean if I can detect what Os I am facing...
To my knowledge, there is not a platform-independent way of determining this. For Windows, check out
GetVersionEx()
."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
Hy folks, I have a little question of reading out the amount of memory that one can use for a program. I know there exists the method filling up the memory until you get an exception, but this isn't a nice way, right? So my question: Is there a way to read out memory specs in windows and other platforms as well? I was just wondering if one of you can thing of a nice platform independent function or approach to calculate the amount of memory available in the system. Also I am interested to find out the amount of processors to calculate the amount of threads for that platform. I am sorry for the leaking of knowledge. :sigh: Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)
modified on Tuesday, March 24, 2009 11:41 AM
You can't compile a program and expect it to then be copied to any computer and run. So, it's not that bad to make a function in your own code that does different things depending on which operating system it is compiled for (you may be cross compiling for all I know) Ie:
DWORD HowManyMegaBytesDoIHave ()
{
#ifdef _WINDOWS
return ThatWindowsAPIFunction ();
#endif
#ifdef _MACOS9
etc}
I hope that made sense. I'm pretty sure the windows one is real, no idea about the other, but they're just meant to illustrate. You'll have to the same #ifdef with the headers too. If you want one codebase to work identically on all OS's, then you'll have to scale back your desires a long way. Good luck, Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
-
You can't compile a program and expect it to then be copied to any computer and run. So, it's not that bad to make a function in your own code that does different things depending on which operating system it is compiled for (you may be cross compiling for all I know) Ie:
DWORD HowManyMegaBytesDoIHave ()
{
#ifdef _WINDOWS
return ThatWindowsAPIFunction ();
#endif
#ifdef _MACOS9
etc}
I hope that made sense. I'm pretty sure the windows one is real, no idea about the other, but they're just meant to illustrate. You'll have to the same #ifdef with the headers too. If you want one codebase to work identically on all OS's, then you'll have to scale back your desires a long way. Good luck, Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
Sorry for the late answer. Of course you are right, what was I thinking?? Spend to much time on Java :). So to conclude either your way, or I simply provide a version of my prog for win and unix. This might be even the cleaner style. Thanks and have a nice weekend. Cheers
You have the thought that modern physics just relay on assumptions, that somehow depends on a smile of a cat, which isn’t there.( Albert Einstein)