Added Array::resize() method

svn-id: r30983
This commit is contained in:
Max Horn 2008-02-27 14:06:06 +00:00
parent 0a918b02fb
commit 142a39da22

View File

@ -159,6 +159,22 @@ public:
}
}
void resize(uint newSize) {
if (newSize == _size)
return;
T *old_data = _data;
_capacity = newSize;
_data = new T[newSize];
if (old_data) {
// Copy old data
int cnt = (_size < newSize ? _size : newSize);
copy(old_data, old_data + cnt, _data);
delete [] old_data;
}
_size = newSize;
}
protected:
void ensureCapacity(uint len) {
if (len >= _capacity)