diff --git a/src/simulator/event-collector.cc b/src/simulator/event-collector.cc index a804df4d8..d47b4cc84 100644 --- a/src/simulator/event-collector.cc +++ b/src/simulator/event-collector.cc @@ -19,10 +19,9 @@ * Author: Gustavo J. A. M. Carneiro */ #include "event-collector.h" -#include #define CLEANUP_CHUNK_MIN_SIZE 8 -#define CLEANUP_CHUNK_MAX_SIZE 1024 +#define CLEANUP_CHUNK_MAX_SIZE 128 namespace ns3 { @@ -46,6 +45,21 @@ EventExpiredPredicate (const EventId &event) return event.IsExpired (); } +void +EventCollector::Grow () +{ + m_nextCleanupSize += (m_nextCleanupSize < CLEANUP_CHUNK_MAX_SIZE? + m_nextCleanupSize : CLEANUP_CHUNK_MAX_SIZE); +} + +void +EventCollector::Shrink () +{ + while (m_nextCleanupSize > m_events.size ()) + m_nextCleanupSize >>= 1; + Grow (); +} + // Called when a new event was added and the cleanup limit was exceeded in consequence. void EventCollector::Cleanup () @@ -54,8 +68,9 @@ EventCollector::Cleanup () // If after cleanup we are still over the limit, increase the limit. if (m_events.size () >= m_nextCleanupSize) - m_nextCleanupSize = std::min (std::list::size_type (CLEANUP_CHUNK_MAX_SIZE), - m_nextCleanupSize<<1); + Grow (); + else + Shrink (); } diff --git a/src/simulator/event-collector.h b/src/simulator/event-collector.h index 7cf7c28db..d0e48460d 100644 --- a/src/simulator/event-collector.h +++ b/src/simulator/event-collector.h @@ -53,6 +53,8 @@ private: std::list m_events; void Cleanup (); + void Grow (); + void Shrink (); }; }; // namespace ns3