0ad/source/lib/allocators/shared_ptr.h
janwas 8e341c2d6b shared_ptr: use Philip's idea of making the Deleter's operator() a template instead of its enclosing class. in code, use DummySharedPtr() instead of passing a DummyDeleter
h_mgr: compile fix for windows memory tracker (see forum thread)
timer: add assert to catch incorrect behaviour as reported by philip

This was SVN commit r5544.
2008-01-10 19:29:52 +00:00

41 lines
681 B
C++

#ifndef INCLUDED_SHARED_PTR
#define INCLUDED_SHARED_PTR
// adapter that allows calling page_aligned_free as a shared_ptr deleter.
class PageAlignedDeleter
{
public:
PageAlignedDeleter(size_t size);
void operator()(u8* p);
private:
size_t m_size;
};
struct DummyDeleter
{
template<class T>
void operator()(T*)
{
}
};
template<class T>
shared_ptr<T> DummySharedPtr(T* ptr)
{
return shared_ptr<T>(ptr, DummyDeleter());
}
struct ArrayDeleter
{
template<class T>
void operator()(T* p)
{
delete[] p;
}
};
// (note: uses CheckedArrayDeleter)
LIB_API shared_ptr<u8> Allocate(size_t size);
#endif // #ifndef INCLUDED_SHARED_PTR