From 1b82f768091214f618abcab605f50f35bee0f381 Mon Sep 17 00:00:00 2001 From: Alexander Krotov Date: Tue, 4 Sep 2018 18:37:12 +0300 Subject: [PATCH] wifi: Remove m_switchToOffEvent to reduce memory consumption WifiRadioEnergyModel::HandleEnergyChanged is called on every state change, and each call produces an event that may not be removed until the end of simulation if there is enough energy. To avoid using a lot of memory, it is necessary to actually remove scheduled events instead of canceling them. --- src/core/model/event-id.cc | 6 ++++++ src/core/model/event-id.h | 5 +++++ src/wifi/model/wifi-radio-energy-model.cc | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/model/event-id.cc b/src/core/model/event-id.cc index a90ceef22..36ad3dc4a 100644 --- a/src/core/model/event-id.cc +++ b/src/core/model/event-id.cc @@ -50,6 +50,12 @@ EventId::EventId (const Ptr &impl, uint64_t ts, uint32_t context, uin NS_LOG_FUNCTION (this << impl << ts << context << uid); } void +EventId::Remove (void) +{ + NS_LOG_FUNCTION (this); + Simulator::Remove (*this); +} +void EventId::Cancel (void) { NS_LOG_FUNCTION (this); diff --git a/src/core/model/event-id.h b/src/core/model/event-id.h index 61185bdb7..28dff8e3b 100644 --- a/src/core/model/event-id.h +++ b/src/core/model/event-id.h @@ -63,6 +63,11 @@ public: * \param [in] uid The unique id for this EventId. */ EventId (const Ptr &impl, uint64_t ts, uint32_t context, uint32_t uid); + /** + * This method is syntactic sugar for the ns3::Simulator::Remove + * method. + */ + void Remove (void); /** * This method is syntactic sugar for the ns3::Simulator::Cancel * method. diff --git a/src/wifi/model/wifi-radio-energy-model.cc b/src/wifi/model/wifi-radio-energy-model.cc index b93df457b..d69266fe9 100644 --- a/src/wifi/model/wifi-radio-energy-model.cc +++ b/src/wifi/model/wifi-radio-energy-model.cc @@ -440,7 +440,7 @@ WifiRadioEnergyModel::HandleEnergyChanged (void) NS_LOG_DEBUG ("WifiRadioEnergyModel:Energy is changed!"); if (m_currentState != WifiPhyState::OFF) { - m_switchToOffEvent.Cancel (); + m_switchToOffEvent.Remove (); Time durationToOff = GetMaximumTimeInState (m_currentState); m_switchToOffEvent = Simulator::Schedule (durationToOff, &WifiRadioEnergyModel::ChangeState, this, WifiPhyState::OFF); } -- 2.17.1