From: Ulya Trofimovich Date: Tue, 25 Jun 2019 21:57:24 +0000 (+0100) Subject: Added 'clear()' method to slab allocator. X-Git-Tag: 1.2~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8f6a38d37f9945912e32b896e70da8b72bf474e2;p=re2c Added 'clear()' method to slab allocator. --- diff --git a/src/util/slab_allocator.h b/src/util/slab_allocator.h index d4ef91bc..d441857f 100644 --- a/src/util/slab_allocator.h +++ b/src/util/slab_allocator.h @@ -27,7 +27,14 @@ class slab_allocator_t public: slab_allocator_t(): slabs_(), current_slab_(0), current_slab_end_(0) {} - ~slab_allocator_t() { std::for_each(slabs_.rbegin(), slabs_.rend(), free); } + ~slab_allocator_t() { clear(); } + + void clear() + { + std::for_each(slabs_.rbegin(), slabs_.rend(), free); + slabs_.clear(); + current_slab_ = current_slab_end_ = 0; + } void *alloc(size_t size) {