diff --git a/dune/common/arraylist.hh b/dune/common/arraylist.hh index fc732a606095ff45c1b3544da41b60b17883ccae..39a987e0018b5e6ab1e8b62a87e6075182d8012e 100644 --- a/dune/common/arraylist.hh +++ b/dune/common/arraylist.hh @@ -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_; diff --git a/dune/common/test/arraylisttest.cc b/dune/common/test/arraylisttest.cc index 9010605dfbc28221886dc8469057fefa5c0a41ef..56ff518e9767170126c0d608064d9f28bfc409d1 100644 --- a/dune/common/test/arraylisttest.cc +++ b/dune/common/test/arraylisttest.cc @@ -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; }