QuIDS: Quantum Irregular Dynamic Simulator
memory.hpp
1/*
2This is the only utilisy that is operating-system dependent !
3*/
4
5#pragma once
6
8namespace quids::utils {
9 #ifdef __CYGWIN__ // windows systems
10
11 #include <windows.h>
12
14 size_t inline get_free_mem() {
15 MEMORYSTATUSEX statex;
16 statex.dwLength = sizeof (statex);
17 GlobalMemoryStatusEx (&statex);
18
19 return statex.AvailPageFile; // free virtual memory instead of free physical memory...
20 }
21
22 #elif defined(__linux__) // linux systems
23
25 size_t inline get_free_mem() {
26 char buff[128];
27 char useless[128];
28 unsigned long free_mem = 0;
29
30 FILE *fd = fopen("/proc/meminfo", "r");
31
32 fgets(buff, sizeof(buff), fd);
33 fgets(buff, sizeof(buff), fd);
34 sscanf(buff, "%s %lu ", useless, &free_mem);
35
36 return free_mem * 1000;
37 }
38
39 #elif defined(__unix__) // other unix systems
40 #error "UNIX system other than LINUX aren't supported for now"
41 #elif defined(__MACH__) // mac os systems
42 #error "macos isn't supported for now !"
43 #else // other systems
44 #error "system isn't supported"
45
47 size_t inline get_free_mem() { return 0; }
48 #endif
49}
QuIDS utility function and variable namespace.
Definition: algorithm.hpp:6
size_t get_free_mem()
function that get the total amount of available free memory.
Definition: memory.hpp:47