How to measure memory usage from inside a C++ program?

Yes – use POSIX getrusage. From the Linux man page: Synopsis #include <sys/time.h> #include <sys/resource.h> int getrusage(int who, struct rusage *usage); Description getrusage() returns current resource usages, for a who of either RUSAGE_SELF or RUSAGE_CHILDREN. The former asks for resources used by the current process, the latter for resources used by those of its children …

Read more