We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent eafcc59 commit a83886bCopy full SHA for a83886b
src/utils/Vector.h
@@ -282,7 +282,14 @@ class Vector {
282
Allocator *p_allocator = &DefaultAllocator;
283
284
void resize_internal(int newSize, bool copy, bool shrink = false) {
285
- if (newSize <= 0) return;
+ 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
293
if (newSize > bufferLen || this->p_data == nullptr || shrink) {
294
T *oldData = p_data;
295
int oldBufferLen = this->bufferLen;
0 commit comments