diff AgentList.h @ 16:33d0b18b2509

Allocate Agents separately on the heap and make AgentList contain pointers only (much quicker)
author Chris Cannam
date Wed, 12 Oct 2011 17:01:57 +0100
parents 887c629502a9
children 03927f6acee2
line wrap: on
line diff
--- a/AgentList.h	Wed Oct 12 10:55:52 2011 +0100
+++ b/AgentList.h	Wed Oct 12 17:01:57 2011 +0100
@@ -31,7 +31,7 @@
 class AgentList
 {
 public:
-    typedef std::vector<Agent> Container;
+    typedef std::vector<Agent *> Container;
     typedef Container::iterator iterator;
 
 protected:
@@ -44,10 +44,10 @@
     Container::iterator begin() { return list.begin(); }
     Container::iterator end() { return list.end(); }
     size_t size() { return list.size(); }
-    void push_back(const Agent &a) {
+    void push_back(Agent *a) {
         list.push_back(a);
 #ifdef DEBUG_BEATROOT
-        std::cerr << "  Added Ag#" << a.idNumber << ", have " << list.size() << " agent(s)" << std::endl;
+        std::cerr << "  Added Ag#" << a->idNumber << ", have " << list.size() << " agent(s)" << std::endl;
 #endif
     }
 
@@ -62,7 +62,7 @@
     static const double DEFAULT_BT;
 
     /** Inserts newAgent into the list in ascending order of beatInterval */
-    void add(Agent a) {
+    void add(Agent *a) {
 	add(a, true);
     } // add()/1
 
@@ -71,7 +71,7 @@
      *  @param newAgent The agent to be added to the list
      *  @param sort Flag indicating whether the list is sorted or not
      */
-    void add(Agent newAgent, bool sort){
+    void add(Agent *newAgent, bool sort){
         push_back(newAgent);
 	if (sort) this->sort();
     } // add()/2