#include <deal.II/base/array_view.h>
+#include <set>
+
+
DEAL_II_NAMESPACE_OPEN
namespace Particles
*/
PropertyPool(const unsigned int n_properties_per_slot);
+ /**
+ * Destructor. This function ensures that all memory that had
+ * previously been allocated using allocate_properties_array()
+ * has also been returned via deallocate_properties_array().
+ */
+ ~PropertyPool();
+
/**
* Return a new handle that allows accessing the reserved block
* of memory. If the number of properties is zero this will return an
* The number of properties that are reserved per particle.
*/
const unsigned int n_properties;
+
+ /**
+ * A collection of handles that have been created by
+ * allocate_properties_array() and have not been destroyed by
+ * deallocate_properties_array().
+ */
+ std::set<Handle> currently_open_handles;
};
{}
+ PropertyPool::~PropertyPool()
+ {
+ Assert(currently_open_handles.size() == 0,
+ ExcMessage("This property pool currently still holds " +
+ std::to_string(currently_open_handles.size()) +
+ " open handles to memory that was allocated "
+ "via allocate_properties_array() but that has "
+ "not been returned via deallocate_properties_array()."));
+ }
+
+
PropertyPool::Handle
PropertyPool::allocate_properties_array()
{
PropertyPool::Handle handle = PropertyPool::invalid_handle;
if (n_properties > 0)
- handle = new double[n_properties];
+ {
+ handle = new double[n_properties];
+ currently_open_handles.insert(handle);
+ }
return handle;
}
void
PropertyPool::deallocate_properties_array(Handle handle)
{
+ Assert(currently_open_handles.count(handle) == 1, ExcInternalError());
+ currently_open_handles.erase(handle);
delete[] handle;
}