How do you determine the amount of Linux system RAM in C++?
问题 I just wrote the following C++ function to programatically determine how much RAM a system has installed. It works, but it seems to me that there should be a simpler way to do this. Can someone tell me if I'm missing something? getRAM() { FILE* stream = popen( "head -n1 /proc/meminfo", "r" ); std::ostringstream output; int bufsize = 128; while( !feof( stream ) && !ferror( stream )) { char buf[bufsize]; int bytesRead = fread( buf, 1, bufsize, stream ); output.write( buf, bytesRead ); } std: