A Discrete-Event Network Simulator
API
ns3::EventGarbageCollector Class Reference

An object that tracks scheduled events and automatically cancels them when it is destroyed. More...

#include "event-garbage-collector.h"

+ Collaboration diagram for ns3::EventGarbageCollector:

Public Member Functions

 EventGarbageCollector ()
 
 ~EventGarbageCollector ()
 
void Track (EventId event)
 Tracks a new event. More...
 

Private Types

typedef std::multiset< EventIdEventList
 Event list container. More...
 

Private Member Functions

void Cleanup ()
 Called when a new event was added and the cleanup limit was exceeded in consequence. More...
 
void Grow ()
 Grow the cleanup limit. More...
 
void Shrink ()
 Shrink the cleanup limit Reduce the cleanup size by factors of two until less than the current event list, then Grow one step. More...
 

Private Attributes

const EventList::size_type CHUNK_INIT_SIZE = 8
 Initial threshold for cleaning the event list. More...
 
const EventList::size_type CHUNK_MAX_SIZE = 128
 Threshold to switch from exponential to linear growth in the cleanup frequency. More...
 
EventList m_events
 The tracked event list. More...
 
EventList::size_type m_nextCleanupSize
 Batch size for cleanup. More...
 

Detailed Description

An object that tracks scheduled events and automatically cancels them when it is destroyed.

It is useful in situations where multiple instances of the same type of event can simultaneously be scheduled, and when the events should be limited to the lifetime of a container object.

Definition at line 46 of file event-garbage-collector.h.

Member Typedef Documentation

◆ EventList

typedef std::multiset<EventId> ns3::EventGarbageCollector::EventList
private

Event list container.

Definition at line 63 of file event-garbage-collector.h.

Constructor & Destructor Documentation

◆ EventGarbageCollector()

ns3::EventGarbageCollector::EventGarbageCollector ( )

Definition at line 32 of file event-garbage-collector.cc.

◆ ~EventGarbageCollector()

ns3::EventGarbageCollector::~EventGarbageCollector ( )

Definition at line 93 of file event-garbage-collector.cc.

References ns3::Simulator::Cancel(), and m_events.

+ Here is the call graph for this function:

Member Function Documentation

◆ Cleanup()

void ns3::EventGarbageCollector::Cleanup ( )
private

Called when a new event was added and the cleanup limit was exceeded in consequence.

Definition at line 67 of file event-garbage-collector.cc.

References Grow(), m_events, m_nextCleanupSize, and Shrink().

Referenced by Track().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Grow()

void ns3::EventGarbageCollector::Grow ( )
private

Grow the cleanup limit.

Increase the cleanup size by the smaller of the current cleanup size (exponential growth), or the CHUNK_MAX_SIZE (linear growth).

Definition at line 48 of file event-garbage-collector.cc.

References CHUNK_MAX_SIZE, and m_nextCleanupSize.

Referenced by Cleanup(), and Shrink().

+ Here is the caller graph for this function:

◆ Shrink()

void ns3::EventGarbageCollector::Shrink ( )
private

Shrink the cleanup limit Reduce the cleanup size by factors of two until less than the current event list, then Grow one step.

Definition at line 55 of file event-garbage-collector.cc.

References Grow(), m_events, and m_nextCleanupSize.

Referenced by Cleanup().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Track()

Member Data Documentation

◆ CHUNK_INIT_SIZE

const EventList::size_type ns3::EventGarbageCollector::CHUNK_INIT_SIZE = 8
private

Initial threshold for cleaning the event list.

Definition at line 66 of file event-garbage-collector.h.

◆ CHUNK_MAX_SIZE

const EventList::size_type ns3::EventGarbageCollector::CHUNK_MAX_SIZE = 128
private

Threshold to switch from exponential to linear growth in the cleanup frequency.

Definition at line 71 of file event-garbage-collector.h.

Referenced by Grow().

◆ m_events

EventList ns3::EventGarbageCollector::m_events
private

The tracked event list.

Definition at line 74 of file event-garbage-collector.h.

Referenced by ~EventGarbageCollector(), Cleanup(), Shrink(), and Track().

◆ m_nextCleanupSize

EventList::size_type ns3::EventGarbageCollector::m_nextCleanupSize
private

Batch size for cleanup.

Definition at line 73 of file event-garbage-collector.h.

Referenced by Cleanup(), Grow(), Shrink(), and Track().


The documentation for this class was generated from the following files: