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
This commit is contained in:
Jason Turner 2009-06-11 22:01:15 +00:00
parent e1727565e6
commit 9838e34a96

View File

@ -46,6 +46,17 @@ class Boxed_Value
false) false)
) )
{ {
void *ptr = boost::any_cast<boost::shared_ptr<T> >(m_data->m_obj).get();
std::map<void *, boost::shared_ptr<Data> >::iterator itr
= m_ptrs.find(ptr);
if (itr != m_ptrs.end())
{
m_data = (itr->second);
} else {
m_ptrs[ptr] = m_data;
}
} }
template<typename T> template<typename T>
@ -56,6 +67,18 @@ class Boxed_Value
true) true)
) )
{ {
void *ptr = boost::any_cast<boost::reference_wrapper<T> >(m_data->m_obj).get_pointer();
std::map<void *, boost::shared_ptr<Data> >::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<typename T> template<typename T>
@ -66,6 +89,8 @@ class Boxed_Value
false) false)
) )
{ {
m_ptrs[boost::any_cast<boost::shared_ptr<T> >(m_data->m_obj).get()]
= m_data;
} }
Boxed_Value(Boxed_Value::Void_Type) Boxed_Value(Boxed_Value::Void_Type)
@ -100,13 +125,6 @@ class Boxed_Value
Boxed_Value &operator=(const Boxed_Value &rhs) Boxed_Value &operator=(const Boxed_Value &rhs)
{ {
m_data = rhs.m_data; 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; return *this;
} }
@ -132,8 +150,10 @@ class Boxed_Value
private: private:
boost::shared_ptr<Data> m_data; boost::shared_ptr<Data> m_data;
static std::map<void *, boost::shared_ptr<Data> > m_ptrs;
}; };
std::map<void *, boost::shared_ptr<Boxed_Value::Data> > Boxed_Value::m_ptrs;
//cast_help specializations //cast_help specializations
template<typename Result> template<typename Result>