From 9bb706c6271e3288829196d87c6d117d8a5ab0fe Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Wed, 2 May 2007 10:41:34 +0200 Subject: [PATCH] destroy prototype stack upon Simulator::Destroy --- src/node/node.cc | 37 +++++++++++++++++++++++++++---------- src/node/node.h | 3 ++- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/node/node.cc b/src/node/node.cc index ab9a6c669..766366722 100644 --- a/src/node/node.cc +++ b/src/node/node.cc @@ -29,8 +29,6 @@ namespace ns3{ -Node::SmartNodeVec_t Node::g_prototypes; // The node prototypes stack - Node::Node() : m_id(0), m_sid(0) { @@ -113,6 +111,18 @@ Node::GetNodeVector (void) return &vector; } +Node::SmartNodeVec_t ** +Node::GetPrototypeVector (void) +{ + static SmartNodeVec_t *vector = 0; + if (vector == 0) + { + vector = new SmartNodeVec_t (); + Simulator::ScheduleDestroy (&Node::DestroyPrototypes); + } + return &vector; +} + void Node::DestroyNodes (void) { @@ -120,11 +130,18 @@ Node::DestroyNodes (void) delete *vector; *vector = 0; } +void +Node::DestroyPrototypes (void) +{ + SmartNodeVec_t **vector = GetPrototypeVector (); + delete *vector; + *vector = 0; +} // Node stack creation and management routines. Node* Node::Create() { - Node* n = g_prototypes.Back()->Copy(); // Copy the top of the stack + Node* n = (*GetPrototypeVector ())->Back()->Copy(); // Copy the top of the stack (*GetNodeVector ())->Add (n); NodeList::Add (n); // Add to global list of nodes return n; @@ -140,30 +157,30 @@ Node* Node::Create(uint32_t sid) Node* Node::GetNodePrototype() { // Get node* to top of prototypes stack - return g_prototypes.Back(); + return (*GetPrototypeVector ())->Back(); } Node* Node::PushNodePrototype(const Node& n) { // Add a new node to the top of the prototypes stack - g_prototypes.Add(n.Copy()); - return g_prototypes.Back(); + (*GetPrototypeVector ())->Add(n.Copy()); + return (*GetPrototypeVector ())->Back(); } Node* Node::PushNodePrototype() { // Replicate the top of the prototype stack - g_prototypes.Add(GetNodePrototype()->Copy()); - return g_prototypes.Back(); + (*GetPrototypeVector ())->Add(GetNodePrototype()->Copy()); + return (*GetPrototypeVector ())->Back(); } void Node::PopNodePrototype() { - if (!g_prototypes.Empty()) g_prototypes.Remove(); + if (!(*GetPrototypeVector ())->Empty()) (*GetPrototypeVector ())->Remove(); } void Node::ClearAll() { // Delete all nodes for memory leak checking, including prototypes (*GetNodeVector ())->Clear (); - g_prototypes.Clear(); + (*GetPrototypeVector ())->Clear(); } L3Demux* diff --git a/src/node/node.h b/src/node/node.h index 18fdec7d6..36fc422d8 100644 --- a/src/node/node.h +++ b/src/node/node.h @@ -165,10 +165,11 @@ public: // Global static variables private: static uint32_t g_nextId; // Next available ID - static SmartNodeVec_t g_prototypes; // Node prototype stack static Node::SmartNodeVec_t **GetNodeVector (void); + static Node::SmartNodeVec_t **GetPrototypeVector (void); static void DestroyNodes (void); + static void DestroyPrototypes (void); protected: void SetId(uint32_t); // NodeList::Add() calls this