Created
July 4, 2016 15:51
-
-
Save alejolp/b1480a95f6eef9c46fc2bbdd3d84c986 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/intrusive_ptr.hpp> | |
#include <boost/smart_ptr/intrusive_ref_counter.hpp> | |
// boost intrusive pointer example | |
// change boost::thread_unsafe_counter to boost::thread_safe_counter for a thread safe version | |
// you shouldn't be passing smart pointer among threads anyway... | |
class Object : private boost::noncopyable, public boost::intrusive_ref_counter<Object, boost::thread_unsafe_counter> { | |
protected: | |
public: | |
Object(); | |
virtual ~Object(); | |
}; | |
typedef boost::intrusive_ptr<Object> ObjectPtr; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/pool/object_pool.hpp> | |
// boost memory pool example | |
class Object { | |
private: | |
static boost::object_pool<Object> s_Pool; | |
public: | |
void* operator new(size_t sz) | |
{ | |
return s_Pool.malloc(); | |
} | |
void operator delete(void* p) | |
{ | |
s_Pool.free(static_cast<Object*>(p)); | |
} | |
public: | |
// ... | |
Object() {} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment