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

Applied Olvers perfectly working patch.

Removed exit of the test program. Now the destructors are called and
there are no leaks any more.

[[Imported from SVN: r5731]]
parent 22cc696a
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
#include <cassert>
#include <vector>
#include "smartpointer.hh"
#include "shared_ptr.hh"
#include "array.hh"
#include "iteratorfacades.hh"
......@@ -197,11 +197,17 @@ namespace Dune
private:
/**
* @brief The allocators for the fixed array.
* @brief The allocators for the smart pointer.
*/
typedef typename A::template rebind<SmartPointer<array<MemberType,chunkSize_> > >::other
typedef typename A::template rebind<shared_ptr<array<MemberType,chunkSize_> > >::other
SmartPointerAllocator;
/**
* @brief The allocator for the fixed array.
*/
typedef typename A::template rebind<array<MemberType,chunkSize_> >::other
ArrayAllocator;
/**
* @brief The iterator needs access to the private variables.
*/
......@@ -209,7 +215,7 @@ namespace Dune
friend class ConstArrayListIterator<T,N,A>;
/** @brief the data chunks of our list. */
std::vector<SmartPointer<array<MemberType,chunkSize_> >,
std::vector<shared_ptr<array<MemberType,chunkSize_> >,
SmartPointerAllocator> chunks_;
/** @brief The current data capacity. */
size_type capacity_;
......@@ -491,7 +497,7 @@ namespace Dune
size_t index=start_+size_;
if(index==capacity_)
{
chunks_.push_back(SmartPointer<array<MemberType,chunkSize_> >());
chunks_.push_back(shared_ptr<array<MemberType,chunkSize_> >(new array<MemberType,chunkSize_>()));
capacity_ += chunkSize_;
}
elementAt(index)=entry;
......@@ -557,7 +563,7 @@ namespace Dune
// Number of chunks with entries in it;
size_t chunks = ((start_%chunkSize_ + size_)/chunkSize_ );
typedef typename std::vector<SmartPointer<array<MemberType,
typedef typename std::vector<shared_ptr<array<MemberType,
chunkSize_> > >::iterator iterator;
// Copy chunks to the left.
......@@ -701,8 +707,11 @@ namespace Dune
list_->start_ = position_;
// Deallocate memory not needed any more.
for(size_t chunk=0; chunk<chunks; chunk++)
list_->chunks_[--posChunkStart].deallocate();
for(size_t chunk=0; chunk<chunks; chunk++) {
--posChunkStart;
assert(list_->chunks_[posChunkStart] && list_->chunks_[posChunkStart].use_count()==1);
list_->chunks_[posChunkStart].reset();
}
// As new entries only get append the capacity shrinks
list_->capacity_-=chunks*chunkSize_;
......
......@@ -178,6 +178,7 @@ int main(){
ArrayList<double,100> alist;
randomizeList(alist);
int ret=testIterator(alist);
if(0!=testComparison()) {
......@@ -199,6 +200,6 @@ int main(){
ret++;
cerr<< "Erasing failed!"<<endl;
}
exit(ret);
return ret;
}
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