diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/oldpool.cpp | 1 | ||||
-rw-r--r-- | src/oldpool.h | 5 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/oldpool.cpp b/src/oldpool.cpp index 6a04eeee3..3cc5c8391 100644 --- a/src/oldpool.cpp +++ b/src/oldpool.cpp @@ -33,6 +33,7 @@ void OldMemoryPoolBase::CleanPool() this->total_items = 0; this->current_blocks = 0; this->blocks = NULL; + this->first_free_index = 0; } /** diff --git a/src/oldpool.h b/src/oldpool.h index 5e5b53c59..6802cb63e 100644 --- a/src/oldpool.h +++ b/src/oldpool.h @@ -42,6 +42,7 @@ protected: uint total_items; ///< How many items we now have in this pool public: + uint first_free_index; ///< The index of the first free pool item in this pool byte **blocks; ///< An array of blocks (one block hold all the items) /** @@ -170,6 +171,7 @@ struct PoolItem { */ virtual ~PoolItem() { + if (this->index < Tpool->first_free_index) Tpool->first_free_index = this->index; } /** @@ -259,8 +261,9 @@ private: */ static T *AllocateRaw() { - for (T *t = Tpool->Get(0); t != NULL; t = (t->index + 1U < Tpool->GetSize()) ? Tpool->Get(t->index + 1U) : NULL) { + for (T *t = Tpool->Get(Tpool->first_free_index); t != NULL; t = (t->index + 1U < Tpool->GetSize()) ? Tpool->Get(t->index + 1U) : NULL) { if (!t->IsValid()) { + Tpool->first_free_index = t->index; Tid index = t->index; memset(t, 0, sizeof(T)); |