DynamicList improvements/disambiguities

* DynamicList::allocSize(label)
  - Adjust the allocated size. The addressed list can be truncated but not
    extended, use setSize() for that.

* DynamicList::reserve(label)
  - Reserve allocation for *at least* this number of elements.
    Never shrinks the allocated size, nor touches the addressed list size.

* DynamicList::setSize(label)
  - proposed behaviour:
    Adjust the addressed list size, allocating extra space if required.
  - The current behaviour is ambiguous about what addressable size will
    actually get set and using it to extend the addressable size (as
    per List) automatically shrinks the allocated space to this size!
This commit is contained in:
Mark Olesen
2008-11-23 12:17:11 +01:00
parent e72a6234d6
commit 129e16f975
3 changed files with 94 additions and 34 deletions

View File

@ -43,9 +43,14 @@ int main(int argc, char *argv[])
ldl[0](3) = 3;
ldl[0](1) = 1;
ldl[0].setSize(5); // increase allocated size
ldl[1].setSize(10); // increase allocated size
ldl[1](2) = 2;
ldl[0].allocSize(5); // increase allocated size
ldl[1].allocSize(10); // increase allocated size
ldl[0].reserve(15); // should increase allocated size
ldl[1].reserve(5); // should not decrease allocated size
ldl[1](3) = 2; // allocates space and sets value
// this works without a segfault, but doesn't change the list size
ldl[0][4] = 4;
ldl[1] = 3;
@ -78,7 +83,7 @@ int main(int argc, char *argv[])
{
dlA.append(i);
}
dlA.setSize(10);
dlA.allocSize(10);
Info<< "<dlA>" << dlA << "</dlA>" << nl << "sizes: "
<< " " << dlA.size() << "/" << dlA.allocSize() << endl;
@ -95,7 +100,6 @@ int main(int argc, char *argv[])
Info<< "<dlB>" << dlB << "</dlB>" << nl << "sizes: "
<< " " << dlB.size() << "/" << dlB.allocSize() << endl;
return 0;
}