mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
DynamicList bugfixes
- transfer(DynamicList&) now preserves the allocated space as-is - operator=(const List&) should now avoid spurious allocation/deallocation
This commit is contained in:
@ -53,7 +53,7 @@ int main(int argc, char *argv[])
|
||||
forAll(ldl, i)
|
||||
{
|
||||
Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize();
|
||||
}
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
List<List<label> > ll(2);
|
||||
@ -64,11 +64,38 @@ int main(int argc, char *argv[])
|
||||
forAll(ldl, i)
|
||||
{
|
||||
Info<< " " << ldl[i].size() << "/" << ldl[i].allocSize();
|
||||
}
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
Info<< "<ll>" << ll << "</ll>" << nl << endl;
|
||||
|
||||
|
||||
// test the transfer between DynamicLists
|
||||
DynamicList<label, 1, 0> dlA;
|
||||
DynamicList<label, 1, 0> dlB;
|
||||
|
||||
for (label i = 0; i < 5; i++)
|
||||
{
|
||||
dlA.append(i);
|
||||
}
|
||||
dlA.setSize(10);
|
||||
|
||||
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
|
||||
<< " " << dlA.size() << "/" << dlA.allocSize() << endl;
|
||||
|
||||
dlB.transfer(dlA);
|
||||
|
||||
// provokes memory error if previous transfer did not maintain
|
||||
// the correct allocated space
|
||||
dlB[6] = 6;
|
||||
|
||||
Info<< "Transferred to dlB" << endl;
|
||||
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
|
||||
<< " " << dlA.size() << "/" << dlA.allocSize() << endl;
|
||||
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
|
||||
<< " " << dlB.size() << "/" << dlB.allocSize() << endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -128,7 +128,7 @@ inline void
|
||||
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer(List<T>& lst)
|
||||
{
|
||||
allocSize_ = lst.size();
|
||||
List<T>::transfer(lst); // take over storage, null lst
|
||||
List<T>::transfer(lst); // take over storage, clear addressing for lst.
|
||||
}
|
||||
|
||||
|
||||
@ -139,8 +139,11 @@ Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::transfer
|
||||
DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
|
||||
)
|
||||
{
|
||||
allocSize_ = lst.allocSize();
|
||||
List<T>::transfer(lst); // take over storage, null lst.
|
||||
// take over storage as-is (without shrink), clear addressing for lst.
|
||||
allocSize_ = lst.allocSize_;
|
||||
lst.allocSize_ = 0;
|
||||
|
||||
List<T>::transfer(static_cast<List<T>&>(lst));
|
||||
}
|
||||
|
||||
|
||||
@ -230,10 +233,13 @@ inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
|
||||
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
|
||||
inline void Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::operator=
|
||||
(
|
||||
const List<T>& l
|
||||
const List<T>& lst
|
||||
)
|
||||
{
|
||||
List<T>::operator=(l);
|
||||
// make the entire storage available for the copy operation:
|
||||
List<T>::size(allocSize_);
|
||||
|
||||
List<T>::operator=(lst);
|
||||
allocSize_ = List<T>::size();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user