|
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.
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 structure MEMORYSTATUSEX 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 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?
|
|
|
|
|
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
|
|
|
|
|
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)
|
|
|
|
|
Hello.
My program gets "segmentation fault" in "strcat(string,stringaux)" and it is strange because I am sure that string always has space for adding the new stringaux due to before call strcat I check if size of the destiny plus new stringaux is less than string capacity:
char string[100];
char stringaux[3];
void Function()
{
if ((strlen(string)+strlen(stringaux))<100)
{
strcat(string,stringaux)
}
}
In this way strcat() never can make string be longer than 100. But still I get SEGMENTATION DEFAULT.
I have been reading, and the explanation can be that the Stack gets full due to I have many local variables or ...
Is there anybody can tell me some ideas about why SEGMENTATION DEFAULT is produced in strcat() when I am sure that is not because there is not space in the destiny string?
Thanks in advance.
|
|
|
|
|
Are you completely sure the segfault comes from strcat? How did you determine this (setting breakpoints, putting traces in the code...)?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Because If I add a comment in the strcat() the segmentation fault does not appear and if I take the comment away the segmentation fault appears.
|
|
|
|
|
Hmm...what happens if you increate the string buffer to -let's say- 150 chars? Or increase your stringaux to -let's say- 10 chars? Does anything change? Also, before the strcat, try displaying the 2 strings to see what is in them, printf or puts should do it...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Remember that strlen returns the length without the terminating null character.
|
|
|
|
|
That is not the point!
Even if I am taking care your comment and in the example I change <100 by <99 the problem is not there.
Because as I said before I am sure that the segmentation fault is not because there is not space in the destiny, even if I make bigger the destiny [1000] I still get the segmentation fault.
|
|
|
|
|
strcat() appends source to destination, overwriting the null character. Does string have one?
"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
|
|
|
|
|
Probably yes, since strlen appears (or as someone already suspected, maybe that the segmention fault occur before the actual call to strcat ) to succeed.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yeah, I did not bother to fully scrutinize his code. It's possible that stringaux has a '\0' but not within the 3 bytes allocated to it.
"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
|
|
|
|
|
DavidCrow wrote: It's possible that stringaux has a '\0' but not within the 3 bytes allocated to it.
But, I suppose, that doesn't harm (it is string the indictee...).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am sure that the problem is in strcat and not in strlen.
|
|
|
|
|
Why?
Could you please post a test case (i.e. the input values for the two string) showing the failure?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Can you tell me, Which compiler you are using?
I have tried with same code given above with gcc compiler in Debian, I doesn't get any Segmentation fault.
Its may be because of your compiler.
I too faced the Same problem when i tried to get the String in run time, in tcc. then later I tried with gcc it worked perfectly..
|
|
|
|
|
Hello,
Can a RUNTIME_CLASS macro have a class with parameters ?
CMDIFrameWnd* pFrame = STATIC_DOWNCAST(CMDIFrameWnd,AfxGetApp()->m_pMainWnd);
CString str = "string";
pFrame->CreateNewChild(RUNTIME_CLASS(TableF(str),IDR_KTYPE, m_hMDIMenu, m_hMDIAccel);
Prithaa
|
|
|
|
|
RUNTIME_CLASS macro will only take class name as parameter.
prvn
|
|
|
|
|
Hello,
Thanks for your reply.
CMDIFrameWnd* pFrame = STATIC_DOWNCAST(CMDIFrameWnd,AfxGetApp()->m_pMainWnd);
CString str = "string";
pFrame->CreateNewChild(RUNTIME_CLASS(TableF(str),IDR_KTYPE, m_hMDIMenu, m_hMDIAccel);
so when I am making this window and I want to pass parameters what should be done.How can I trace the object of this window.
Pritha
|
|
|
|