Menu

Home

Thomas Sparber

Hi C/C++ developer!

With meminfo you can get memory information about your process or other processes.

Example

The following code demonstrates how it works:

//Initial memory usage
printMemUsage();

//Memory usage after stack allocation
char c[1024];
printMemUsage();

//Memory usage after heap allocation
char *test = (char*)malloc(sizeof(char) * 409600);
printMemUsage();

//Memory usage after heap deallocation
free(test);
printMemUsage();

printMemUsage does the following:

static struct meminfo m;
get_own_meminfo(&m);
printf("Referenced: %d kB\n", m.referenced_KB);

This will print the following:
Referenced: 468 kB
Referenced: 480 kB
Referenced: 484 kB
Referenced: 480 kB

This code is included in test.c

Performance

My Raspberry Pi is able to perform 1000 measures in 1.51 seconds

Thanks and have fun coding!


MongoDB Logo MongoDB