If your code is in C or C++ you might be able to use getrusage()
which returns you various statistics about memory and time usage of your process.
Not all platforms support this though and will return 0 values for the memory-use options.
Instead you can look at the virtual file created in /proc/[pid]/statm
(where [pid]
is replaced by your process id. You can obtain this from getpid()
).
This file will look like a text file with 7 integers. You are probably most interested in the first (all memory use) and sixth (data memory use) numbers in this file.