Commit a31eedec authored by incardon's avatar incardon
Browse files

Adding functions to destroy memory

parent 874297aa
......@@ -669,6 +669,26 @@ public:
e_invalid.clear();
}
/*! \brief operator to clear the whole graph
*
* operator to clear all
*
*/
void destroy()
{
v.clear();
v.shrink_to_fit();
e.clear();
e.shrink_to_fit();
v_l.clear();
v_l.shrink_to_fit();
e_l.clear();
e_l.shrink_to_fit();
e_invalid.clear();
e_invalid.shrink_to_fit();
}
/*! \brief Access the edge
*
* \tparam i property to access
......
......@@ -995,6 +995,14 @@ public:
Mem_type::clear();
}
/*! \brief Litterary destroy the memory of the cell list, including the retained one
*
*/
void destroy()
{
Mem_type::destroy();
}
/*! \brief Return the starting point of the cell p
*
* \param cell_id cell id
......
......@@ -235,6 +235,20 @@ protected:
cl_n.get(i) = 0;
}
/*! \brief Destroy the memory
*
*
*
*/
inline void destroy()
{
cl_n.resize(0);
cl_base.resize(0);
cl_n.shrink_to_fit();
cl_base.shrink_to_fit();
}
/*! \brief Get the first element of a cell (as reference)
*
* \param cell_id cell-id
......
......@@ -204,6 +204,20 @@ namespace openfpm
resize(0);
}
/*! \brief Clear the vector
*
* Eliminate all the elements for from the vector
*
*/
void shrink_to_fit()
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
size_t sz[1] = {size()};
base.resize(sz);
}
/*! \brief Resize the vector
*
* Resize the vector and allocate n elements
......
......@@ -96,8 +96,8 @@ struct add_prp_impl<OBJECT_ADD,vect_dst>
* \param T base type
*
*/
template<typename T>
class vector<T,HeapMemory,typename memory_traits_lin<T>::type,memory_traits_lin,grow_policy_double,STD_VECTOR>
template<typename T, typename grow_p>
class vector<T,HeapMemory,typename memory_traits_lin<T>::type,memory_traits_lin,grow_p,STD_VECTOR>
{
// Memory layout
typedef typename memory_traits_lin<T>::type layout;
......@@ -171,6 +171,17 @@ public:
base.clear();
}
/*! \brief Fit the memory to the size of the vector
*
*/
inline void shrink_to_fit()
{
#ifdef SE_CLASS2
check_valid(this,8);
#endif
base.shrink_to_fit();
}
/*! \brief It insert a new object on the vector, eventually it reallocate the grid
*
* \param v element to add
......@@ -187,6 +198,12 @@ public:
void * ptr_old = &base[0];
#endif
if (std::is_same<grow_p,openfpm::grow_policy_identity>::value == true)
{
// we reserve just one space more to avoid the capacity to increase by two
base.reserve(base.size()+1);
}
base.push_back(v);
#ifdef SE_CLASS2
......@@ -216,6 +233,12 @@ public:
void * ptr_old = &base[0];
#endif
if (std::is_same<grow_p,openfpm::grow_policy_identity>::value == true)
{
// we reserve just one space more to avoid the capacity to increase by two
base.reserve(base.size()+1);
}
base.emplace_back(v);
#ifdef SE_CLASS2
......@@ -265,6 +288,12 @@ public:
void * ptr_old = &base[0];
#endif
if (std::is_same<grow_p,openfpm::grow_policy_identity>::value == true)
{
// we reserve just one space more to avoid the capacity to increase by two
base.reserve(base.size() + eles.size());
}
size_t start = base.size();
base.resize(base.size() + eles.size());
......@@ -282,7 +311,7 @@ public:
#endif
}
/*! \brief It insert a new object on the vector, eventually it reallocate the grid
/*! \brief It insert a new object on the vector, eventually it reallocate the object
*
* \param v element to add
*
......@@ -327,6 +356,12 @@ public:
void * ptr_old = &base[0];
#endif
if (std::is_same<grow_p,openfpm::grow_policy_identity>::value == true)
{
// we reserve just one space more to avoid the capacity to increase by two
base.reserve(base.size() + 1);
}
base.push_back(v);
#ifdef SE_CLASS2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment