mem_test.cpp 590 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <iostream>
  2. #include <vector>
  3. #include <thread>
  4. #include <chrono>
  5. //#include "sys/types.h"
  6. //#include "sys/sysinfo.h"
  7. #include <sys/time.h>
  8. #include <sys/resource.h>
  9. #include "../cpptime.h"
  10. using namespace std;
  11. using namespace std::chrono;
  12. std::vector<int> x;
  13. void func(CppTime::timer_id) {
  14. int who = RUSAGE_SELF;
  15. struct rusage usage;
  16. int ret;
  17. ret=getrusage(who,&usage);
  18. cout<<usage.ru_maxrss << "\n";
  19. x.resize(x.size() * 2);
  20. }
  21. int main() {
  22. x.resize(1000);
  23. CppTime::Timer t;
  24. auto id = t.add(seconds(2), func, seconds(1));
  25. while(1) ;
  26. t.remove(id);
  27. }