
Hi All, This is my first post though so please bear with my sentences. I have used scoped_ptr but this is too tied with new/delete semantics i.e. can't use it with pointers which gets allocated from specialized memory area. class AManager { public: A * allocate(); void deallocate(A * p); }; class A { ..... }; This specially happens when I use scoped pointer for C like pointers/allocator: Can I modify scoped pointer to have release semantics which is user defined: template<typename T> class DefaultReleasePolicy { static void releaseA(T * p) { delete p; } }; class ReleaseAPolicy { static void releaseA(A * p) { AManager::getInstance()->deallocate(p); } }; template<typename T,typemame ReleasePolicy = DefaultReleasePolicy<T> > class ScopedPtrModified { ~ScopedPtrModified() { ReleasePolicy::release(m_ptr); } }; Is this fine? Let me know your thoughts. Regards, Rahul

why not just use unique_ptr with custom deleter function? On Sun, Dec 9, 2012 at 9:02 AM, Rahul Sr <srivasrrahul@gmail.com> wrote:
Hi All, This is my first post though so please bear with my sentences.
I have used scoped_ptr but this is too tied with new/delete semantics i.e. can't use it with pointers which gets allocated from specialized memory area.
class AManager { public: A * allocate(); void deallocate(A * p); };
class A { ..... };
This specially happens when I use scoped pointer for C like pointers/allocator:
Can I modify scoped pointer to have release semantics which is user defined:
template<typename T> class DefaultReleasePolicy { static void releaseA(T * p) { delete p; } };
class ReleaseAPolicy { static void releaseA(A * p) { AManager::getInstance()->deallocate(p); } };
template<typename T,typemame ReleasePolicy = DefaultReleasePolicy<T> > class ScopedPtrModified { ~ScopedPtrModified() { ReleasePolicy::release(m_ptr);
} };
Is this fine? Let me know your thoughts.
Regards, Rahul
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Regards, Arpan ----------------------------------------------------------------------------------------------------------------- Reality is merely an illusion, albeit a very persistent one.

Thanks for input it does serve me well for some of the cases (where a single copy is required). However I face similar problem for shared_ptr as well. When ref count is 0 it will only call delete. Is there a way I can add mine? Regards, Rahul On Sun, Dec 9, 2012 at 5:34 PM, Arpan Sen <arpansen@gmail.com> wrote:
why not just use unique_ptr with custom deleter function?
On Sun, Dec 9, 2012 at 9:02 AM, Rahul Sr <srivasrrahul@gmail.com> wrote:
Hi All, This is my first post though so please bear with my sentences.
I have used scoped_ptr but this is too tied with new/delete semantics i.e. can't use it with pointers which gets allocated from specialized memory area.
class AManager { public: A * allocate(); void deallocate(A * p); };
class A { ..... };
This specially happens when I use scoped pointer for C like pointers/allocator:
Can I modify scoped pointer to have release semantics which is user defined:
template<typename T> class DefaultReleasePolicy { static void releaseA(T * p) { delete p; } };
class ReleaseAPolicy { static void releaseA(A * p) { AManager::getInstance()->deallocate(p); } };
template<typename T,typemame ReleasePolicy = DefaultReleasePolicy<T> > class ScopedPtrModified { ~ScopedPtrModified() { ReleasePolicy::release(m_ptr);
} };
Is this fine? Let me know your thoughts.
Regards, Rahul
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
-- Regards, Arpan
----------------------------------------------------------------------------------------------------------------- Reality is merely an illusion, albeit a very persistent one.

On December 9, 2012 5:41:01 PM Rahul Sr <srivasrrahul@gmail.com> wrote:
Thanks for input it does serve me well for some of the cases (where a single copy is required). However I face similar problem for shared_ptr as well. When ref count is 0 it will only call delete. Is there a way I can add mine?
You can specify a custom deleter as the second parameter of the initializing constructor.
participants (3)
-
Andrey Semashev
-
Arpan Sen
-
Rahul Sr