diff --git a/libacc/acc.cpp b/libacc/acc.cpp index 22cfb55f7..8f33b0bdd 100644 --- a/libacc/acc.cpp +++ b/libacc/acc.cpp @@ -82,9 +82,7 @@ template class Vector { ~Vector() { if (mpBase) { - for(size_t i = 0; i < mUsed; i++) { - mpBase[mUsed].~E(); - } + clear(); free(mpBase); } } @@ -110,10 +108,20 @@ template class Vector { * ensure(1) = item; } - size_t size() { + inline size_t size() { return mUsed; } + void clear() { + if (mpBase) { + size_t used = mUsed; + for(size_t i = 0; i < used; i++) { + mpBase[i].~E(); + } + } + mUsed = 0; + } + private: E* ensure(int n) { size_t newUsed = mUsed + n;