Skip to content

Instantly share code, notes, and snippets.

@yoya
Last active December 26, 2018 08:01
Show Gist options
  • Save yoya/4388406131d45966dd3ef9c550618505 to your computer and use it in GitHub Desktop.
Save yoya/4388406131d45966dd3ef9c550618505 to your computer and use it in GitHub Desktop.
shared_ptr exercise
// g++ -std=c++11 shared.cc
#include <iostream>
#include <memory>
#include <sys/time.h>
#include <sys/resource.h>
class A {
private:
char a[0x10000000];
};
typedef std::shared_ptr<A> Aptr;
// typedef A *Aptr;
Aptr getA(void) {
Aptr a(new A());
return a;
}
int main(void) {
struct rusage rusage;
for (int i = 0 ; i < 1000 ; i++) {
Aptr a = getA();
getrusage( RUSAGE_SELF, &rusage );
std::cout << rusage.ru_maxrss << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment