Skip to content

Commit a83886b

Browse files
committed
Support to resize a vector to 0
1 parent eafcc59 commit a83886b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/utils/Vector.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,14 @@ class Vector {
282282
Allocator *p_allocator = &DefaultAllocator;
283283

284284
void resize_internal(int newSize, bool copy, bool shrink = false) {
285-
if (newSize <= 0) return;
285+
if (newSize <= 0 && p_data==nullptr) return;
286+
// release memory
287+
if (newSize <= 0) {
288+
deleteArray(p_data, size()); // delete [] this->p_data;
289+
p_data = nullptr;
290+
return;
291+
}
292+
// allocate new memory
286293
if (newSize > bufferLen || this->p_data == nullptr || shrink) {
287294
T *oldData = p_data;
288295
int oldBufferLen = this->bufferLen;

0 commit comments

Comments
 (0)