Skip to content
Snippets Groups Projects
Commit 045f5fda authored by Dan Vonk's avatar Dan Vonk Committed by Daniel Vonk
Browse files

Fix memory leak in IAtomselection

parent fec9d0bd
No related branches found
No related tags found
2 merge requests!19Merge develop into main,!17Add CUDA backend
......@@ -23,68 +23,80 @@ This file contains a class which defines different types of atomselections.
/**
Interface for atom selections.
*/
class IAtomselection {
protected:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {}
public:
virtual size_t operator[](size_t index) = 0;
virtual size_t size() = 0;
class IAtomselection
{
protected:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
}
public:
virtual size_t operator[](size_t index) = 0;
virtual size_t size() = 0;
virtual ~IAtomselection() {};
};
/**
An atom selection which is implemented as an array of atom indexes. May use up
significant amount of memory.
*/
class IndexAtomselection : public IAtomselection {
// make this class serializable to
// allow sample to be transmitted via MPI
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<IAtomselection, IndexAtomselection>(
*this);
ar& ids_;
}
///////////////////
std::vector<size_t> ids_;
public:
IndexAtomselection() {}
IndexAtomselection(std::vector<size_t> ids);
size_t operator[](size_t index);
size_t size();
class IndexAtomselection : public IAtomselection
{
// make this class serializable to
// allow sample to be transmitted via MPI
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar &boost::serialization::base_object<IAtomselection, IndexAtomselection>(*this);
ar & ids_;
}
///////////////////
std::vector<size_t> ids_;
public:
IndexAtomselection()
{
}
IndexAtomselection(std::vector<size_t> ids);
size_t operator[](size_t index);
size_t size();
};
/**
Selects atoms within the given range. No memory requirements and is used e.g.
for the system selection.
*/
class RangeAtomselection : public IAtomselection {
// make this class serializable to
// allow sample to be transmitted via MPI
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& ar, const unsigned int version) {
ar& boost::serialization::base_object<IAtomselection, RangeAtomselection>(
*this);
ar& from_;
ar& to_;
}
///////////////////
size_t from_;
size_t to_;
public:
RangeAtomselection() : from_(0), to_(0) {}
RangeAtomselection(size_t from, size_t to);
size_t operator[](size_t index);
size_t size();
class RangeAtomselection : public IAtomselection
{
// make this class serializable to
// allow sample to be transmitted via MPI
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive &ar, const unsigned int version)
{
ar &boost::serialization::base_object<IAtomselection, RangeAtomselection>(*this);
ar & from_;
ar & to_;
}
///////////////////
size_t from_;
size_t to_;
public:
RangeAtomselection()
: from_(0)
, to_(0)
{
}
RangeAtomselection(size_t from, size_t to);
size_t operator[](size_t index);
size_t size();
};
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment