system requirements

Started by
5 comments, last by BloodSweatAndCode 22 years, 10 months ago
Let''s say you want to make a minimum system requirements for your OpenGL program. How would you determine how much RAM your program is using. I know MFC has the CMemoryState class but that only gives the memory Using the malloc/free family of functions AND Using the C++ new and delete operators. I want to be able to know the RAM of EVEYTHING. Thanks.
You''re not a programmer until that moment you stop yourself from destroying your computer into a billion- million pieces
Advertisement
If you''re using NT, I think there is a system monitor tool that shows current memory usage per process. For 9x there are several similar third-party tools.
unsigned short int -> 2 bytes
short int -> 2 bytes
unsigned long int -> 4 bytes
long int -> 4 bytes
int -> 4 bytes
unsigned int -> 4 bytes
char -> 1 byte
wchar_t -> 2 bytes
bool -> 1 byte
float -> 4 bytes
double -> 8 bytes
long double -> 10 bytes

Assuming you are using a 32-bit computer (most likely), this is how much memory each variable type uses. Add up the amount of bytes your program uses by adding up the value for every variable in your program (don't forget the arrays and structures)... and then divide by 1024 to get KBytes, 1024 again to get MBytes, etc...

Try this:

#include "iostream.h"

int main(void)
{
char *name = new char(6);
unsigned short age;
double *whatever = new double(5);

// (6 * 1bytes) + (1 * 2bytes) + (5 * 8bytes) = 48 bytes

cout << "RAM usage: " <<
((sizeof(char) * 6) + (sizeof(unsigned short) * 1) +
(sizeof(double) * 5)) << " Bytes" << endl;

delete [] name;
delete [] whatever;
return 0;
}

This program *SHOULD* print "RAM usage: 48 Bytes"

To get Kbytes -> 48 / 1024
To get MBytes -> (48 / 1024) / 1024

I'm not sure if the actual executable uses any RAM itself, but I wouldn't doubt it. The value you get with the method above is close enough Keeping track of your variables is a bit tedious though!


Edited by - glDino on June 9, 2001 8:45:11 PM

Edited by - glDino on June 9, 2001 8:46:13 PM
Thanks guys. It really help alot!
You''re not a programmer until that moment you stop yourself from destroying your computer into a billion- million pieces
quote:Original post by glDino

unsigned short int -> 2 bytes
short int -> 2 bytes
unsigned long int -> 4 bytes
long int -> 4 bytes
int -> 4 bytes
unsigned int -> 4 bytes
char -> 1 byte
wchar_t -> 2 bytes
bool -> 1 byte
float -> 4 bytes
double -> 8 bytes
long double -> 10 bytes

Assuming you are using a 32-bit computer (most likely), this is how much memory each variable type uses.


Not entirely correct I think. The size of these types depends on the compiler the program is being compiled on. These seem te be the sizes VC++ uses, but gcc for instance uses different values. So if you want to be albe to compile your programs on anything else than VC++, you should check the size of your types with sizeof, or use __int16 for a short int, etc.
Yeah, your probably right.

I got those values out of a C++ book though (Teach Yourself C++, SAMS publishing) with no specific compiler mentioned... must not be a very good book then ;(

Actually I think most compilers for Intel systems use a standard data size for all types except for long double and long long.

VC++ doesn''t support long long(it''s not ANSI yet) and I think it treats long double exactly the same as double.

The rest are mostly the same on 32-bit Intel systems. If you want to port your game to an Alpha or MIPS system... well.. you need to use sizeof to calculate your memory requirements.

To do it correctly though you want to use a profiler and run your game a whole bunch of times in the profiler and let it determine the minimum memory requirements. In a complex game it is pretty hard to calculate the memory yourself.

Seeya
Krippy

This topic is closed to new replies.

Advertisement