#include #include class myObject{ int i; public: myObject(){} myObject(int i_):i(i_){} int getValue() const {return i;} }; struct A{ }; struct B{ int data; boost::shared_ptr p; }; struct C{ boost::shared_ptr p; }; int main(){ /* WHY POINTERS? */ myObject A(0); // object is allocated on the stack /* stack VS heap */ // small variables on the stack // dynamical memory on the heap == "new" //when running, the OS has allocated the stack size... //when allocatinh by new ==> HEAP, one asks the kernel for space in the system ... takes time! //RULE: in critical loops, do not allocate using new ! //stack: only for objects whose size is known at compile time //array lib : minivector on stack, to avoid allocation problems (ulimit... std::cout << A.getValue()<getValue() << std::endl; std::cout << (*p1).getValue() << std::endl; /* THE ISSUE */ delete(p1); // deletes the pointer but not the underlying data /* SHARED POINTER */ boost::shared_ptr p1_sh(new myObject(1)); std::cout << p1_sh->getValue()< p2_sh = p1_sh; std::cout << p2_sh->getValue()<