Pol  Revision:3cfda13
xmain.cpp
Go to the documentation of this file.
1 
10 #include <stddef.h>
11 #include <stdio.h>
12 #if defined( WINDOWS )
13 #include "Header_Windows.h"
14 
15 #pragma comment( lib, "psapi.lib" ) // 32bit is a bit dumb..
16 #else
17 #include <unistd.h>
18 #endif
19 
20 namespace Pol
21 {
22 namespace Clib
23 {
24 // TODO: create a system.cpp/h and put the following function with some other features in a separate
25 // static class "system"
27 {
28 #if defined( _WIN32 )
29  PROCESS_MEMORY_COUNTERS info;
30  GetProcessMemoryInfo( GetCurrentProcess(), &info, sizeof( info ) );
31  return (size_t)info.WorkingSetSize;
32 
33 #else
34  long rss = 0L;
35  FILE* fp = NULL;
36  if ( ( fp = fopen( "/proc/self/statm", "r" ) ) == NULL )
37  return (size_t)0L; /* Can't open? */
38  if ( fscanf( fp, "%*s%ld", &rss ) != 1 )
39  {
40  fclose( fp );
41  return (size_t)0L; /* Can't read? */
42  }
43  fclose( fp );
44  return (size_t)rss * (size_t)sysconf( _SC_PAGESIZE );
45 #endif
46 }
47 }
48 }
size_t getCurrentMemoryUsage()
returns the current process size in bytes
Definition: xmain.cpp:26
Definition: berror.cpp:12