From 9838e34a965a122df8b4a26c30e5c44f6948bcc4 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 11 Jun 2009 22:01:15 +0000 Subject: [PATCH] First take on recycling of pointers for use in reference objects. Two caveats: 1) Static member defined in header. this will have to be cleaned up as it prevents mult-file compilation. 2) Ptrs are never let go of, so data is never freed, so every object that is ever created is always created --- dispatchkit/boxed_value.hpp | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/dispatchkit/boxed_value.hpp b/dispatchkit/boxed_value.hpp index a15f093..84f08c7 100644 --- a/dispatchkit/boxed_value.hpp +++ b/dispatchkit/boxed_value.hpp @@ -46,6 +46,17 @@ class Boxed_Value false) ) { + void *ptr = boost::any_cast >(m_data->m_obj).get(); + + std::map >::iterator itr + = m_ptrs.find(ptr); + + if (itr != m_ptrs.end()) + { + m_data = (itr->second); + } else { + m_ptrs[ptr] = m_data; + } } template @@ -56,6 +67,18 @@ class Boxed_Value true) ) { + void *ptr = boost::any_cast >(m_data->m_obj).get_pointer(); + + std::map >::iterator itr + = m_ptrs.find(ptr); + + if (itr != m_ptrs.end()) + { + std::cout << "Reference wrapper ptr found, using it" << std::endl; + m_data = (itr->second); + } else { + m_ptrs[ptr] = m_data; + } } template @@ -66,6 +89,8 @@ class Boxed_Value false) ) { + m_ptrs[boost::any_cast >(m_data->m_obj).get()] + = m_data; } Boxed_Value(Boxed_Value::Void_Type) @@ -100,13 +125,6 @@ class Boxed_Value Boxed_Value &operator=(const Boxed_Value &rhs) { m_data = rhs.m_data; - /* - std::cout << "operator= called" << std::endl; - m_data->m_obj = rhs.m_data->m_obj; - m_data->m_type_info = rhs.m_data->m_type_info; - m_data->m_is_ref = rhs.m_data->m_is_ref; - (*m_data) = (*rhs.m_data); - */ return *this; } @@ -132,8 +150,10 @@ class Boxed_Value private: boost::shared_ptr m_data; + static std::map > m_ptrs; }; +std::map > Boxed_Value::m_ptrs; //cast_help specializations template