I wrote two C codes and i wanted to compare them by execution time and RAM memory usage. I got the execution time with no problems. Now, for the RAM memory usage, i got values too, but im having some doubts on interpretating them.
I used two functions to get them.
First one, using the proc filesystem (based on How to determine CPU and memory consumption from inside a process?)
void getValue(){
FILE* file = fopen("/proc/self/status", "r");
char line[128];
while (fgets(line, 128, file) != NULL){
printf("%s", line);
}
fclose(file);
}
In this one, i took the value of VmRSS line.
Second one, using the Getrusage API (based on Memory usage of current process in C):
struct rusage r_usage;
getrusage(RUSAGE_SELF, &r_usage);
printf("%ld\n", r_usage.ru_maxrss);
Using these functions, i got different values, but all of them were between 500KB ~ 700KB. But i found the values strange, and i started to erase variables and functions from one of my codes, until there was only the functions above left inside it. I executed it and the result was a slightly lower value than the previous result.
So, i was expecting some bytes as its size, but it is hundreds of KB. Why does it use more memory that it seems like it should?
I used Ubuntu 20.04 on Windows 10 WLS