Skip to content
Snippets Groups Projects
Commit bc0a4771 authored by Martin Nolte's avatar Martin Nolte
Browse files

valgrind complains unless polymorphic objects are deleted by the destructor,

so modify the interface to only contain create and destroy methods

[[Imported from SVN: r5988]]
parent befd7486
No related branches found
No related tags found
No related merge requests found
......@@ -14,24 +14,15 @@ namespace Dune
struct PolyAllocator
{
template< class T >
T *allocate ( size_t n = 1 )
T *create ( const T &value )
{
return static_cast< T * >( operator new( n * sizeof( T ) ) );
return new T( value );
}
template< class T > void deallocate ( T *p )
{
operator delete( p );
}
template< class T > void construct ( T *p, const T &value )
{
new( p ) T( value );
}
template< class T > void destroy ( T *p )
template< class T >
void destroy ( T *p )
{
p->~T();
delete p;
}
};
......
......@@ -161,11 +161,8 @@ namespace Dune
struct SmallObjectPolyAllocator
{
template< class T > T *allocate ( size_t n = 1 );
template< class T > void deallocate ( T *p );
template< class T > void construct ( T *p, const T &value ) { new( p ) T( value ); }
template< class T > void destroy ( T *p ) { p->~T(); }
template< class T > T *create ( const T &value );
template< class T > void destroy ( T *p );
};
......@@ -208,14 +205,16 @@ namespace Dune
// ------------------------------------------
template< class T >
inline T *SmallObjectPolyAllocator::allocate ( size_t n )
inline T *SmallObjectPolyAllocator::create ( const T &value )
{
return static_cast< T * >( SmallObjectPool::allocate( n * sizeof( T ) ) );
void *address = SmallObjectPool::allocate( sizeof( T ) );
return new( address ) T( value );
}
template< class T >
inline void SmallObjectPolyAllocator::deallocate ( T *p )
inline void SmallObjectPolyAllocator::destroy ( T *p )
{
p.~T();
SmallObjectPool::free( p );
}
......
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