Skip to content
Snippets Groups Projects
Commit cb5be0f2 authored by Markus Blatt's avatar Markus Blatt
Browse files

[bugfix][release] Added missing copy constructor for Pool.

When copying PoolAllocators Bard experienced linking errors to the
copy constructor of Pool, which is deactivated. To fix this we added
the copy constructor. Note that it does not copy the pool such that
ownership of allocated memory chunks is clear.

Kudos go to Bard for noticing this and providing the fix.

In addition we removed the copy constructor of the specialization for
void as the default coy constructor suffices.
parent 2cf4df65
No related branches found
No related tags found
No related merge requests found
......@@ -300,12 +300,25 @@ namespace Dune
inline PoolAllocator();
/**
* @brief Coopy Constructor.
* @brief Copy Constructor that does not copy the memory pool.
*/
template<typename U, std::size_t u>
inline PoolAllocator(const PoolAllocator<U,u>&)
{}
{
// we allow copying but never copy the pool
// to have a clear ownership of allocated pointers.
}
/// \brief Copy constructor that does not copy the memory pool.
PoolAllocator(const PoolAllocator&)
{
// we allow copying but never copy the pool
// to have a clear ownership of allocated pointers.
// For this behaviour we have to implement
// the copy constructor, because the default
// one would copy the pool and deallocation
// of it would break.
}
/**
* @brief Allocates objects.
* @param n The number of objects to allocate. Has to be one!
......@@ -384,11 +397,6 @@ namespace Dune
{
typedef PoolAllocator<U,s> other;
};
template<typename T, std::size_t t>
PoolAllocator(const PoolAllocator<T,t>&)
{}
};
......
......@@ -119,6 +119,28 @@ int testPool()
return ret;
}
int testPoolAllocator()
{
int ret=0;
PoolAllocator<double,10> pool;
double *d=pool.allocate(1);
PoolAllocator<float,5> pool1=pool;
PoolAllocator<double,10> pool2=pool;
try
{
pool2.deallocate(d,1);
++ret;
std::cerr<<"ERROR: allocation should not work with copied allocators."<<std::endl;
}
catch(std::bad_alloc)
{}
pool1.allocate(1);
double *d1=pool2.allocate(1);
pool.deallocate(d,1);
pool2.deallocate(d1,1);
pool2.allocate(1);
return ret;
}
int main(int, char **)
{
int ret=0;
......@@ -131,6 +153,7 @@ int main(int, char **)
ret += testPool<Dune::FieldMatrix<double,10,10> >();
ret+=testPoolAllocator();
std::cout<<AlignmentOf<UnAligned>::value<<" "<<sizeof(UnAligned)<<std::endl;
......
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