summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-29 06:55:25 +0000
committernw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1997-07-29 06:55:25 +0000
commit756221c7e41280d36898e2c7418c94831d5bf261 (patch)
tree914ce6ae12a2fd7c07660521ba2e67efc56582d0
parent5fb98cffe19364e1789996e1be200547c525caae (diff)
downloadATCD-756221c7e41280d36898e2c7418c94831d5bf261.tar.gz
Decouple memory allocation strategy for ACE_Unbounded_Stack,
ACE_Unbounded_Set, ACE_Unbounded_Queue.
-rw-r--r--ace/Containers.cpp99
-rw-r--r--ace/Containers.h25
2 files changed, 86 insertions, 38 deletions
diff --git a/ace/Containers.cpp b/ace/Containers.cpp
index 8b799150e42..51684fa7710 100644
--- a/ace/Containers.cpp
+++ b/ace/Containers.cpp
@@ -127,13 +127,18 @@ ACE_Unbounded_Stack<T>::dump (void) const
}
template<class T>
-ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (void)
+ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (ACE_Allocator *alloc)
: head_ (0),
- cur_size_ (0)
+ cur_size_ (0),
+ allocator_ (alloc)
{
- ACE_NEW (this->head_, ACE_Node<T>);
- this->head_->next_ = this->head_;
// ACE_TRACE ("ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack");
+ if (this->allocator_ == 0)
+ this->allocator_ = ACE_Allocator::instance ();
+
+ ACE_NEW_MALLOC (this->head_, this->allocator_->malloc (sizeof (ACE_NODE<T>)),
+ ACE_NODE<T>);
+ this->head_->next_ = this->head_;
}
template<class T> void
@@ -145,7 +150,7 @@ ACE_Unbounded_Stack<T>::delete_all_nodes (void)
{
ACE_Node<T> *temp = this->head_->next_;
this->head_->next_ = temp->next_;
- delete temp;
+ this->allocator_->free (temp);
}
ACE_ASSERT (this->head_ == this->head_->next_
@@ -165,17 +170,23 @@ ACE_Unbounded_Stack<T>::copy_all_nodes (const ACE_Unbounded_Stack<T> &s)
s_temp != s.head_;
s_temp = s_temp->next_)
{
- ACE_NEW (temp->next_,
- ACE_Node<T> (s_temp->item_, temp->next_));
+ ACE_NEW_MALLOC (temp->next_,
+ this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T> (s_temp->item_, temp->next_));
temp = temp->next_;
}
}
template<class T>
ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack (const ACE_Unbounded_Stack<T> &s)
- : head_ (0)
+ : head_ (0),
+ allocator_ (s.allocator_)
{
- ACE_NEW (this->head_, ACE_Node<T>);
+ if (this->allocator_ == 0)
+ this->allocator_ = ACE_Allocator::instance ();
+
+ ACE_NEW_MALLOC (this->head_, this->allocator_->malloc( sizeof (ACE_Node<T>)),
+ ACE_Node<T>);
this->head_->next_ = this->head_;
// ACE_TRACE ("ACE_Unbounded_Stack<T>::ACE_Unbounded_Stack");
@@ -199,7 +210,7 @@ ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack (void)
// ACE_TRACE ("ACE_Unbounded_Stack<T>::~ACE_Unbounded_Stack");
this->delete_all_nodes ();
- delete this->head_;
+ this->allocator_->free (this->head_);
}
template<class T> int
@@ -209,7 +220,8 @@ ACE_Unbounded_Stack<T>::push (const T &new_item)
ACE_Node<T> *temp = 0;
- ACE_NEW_RETURN (temp, ACE_Node<T> (new_item, this->head_->next_), -1);
+ ACE_NEW_MALLOC_RETURN (temp, this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T> (new_item, this->head_->next_), -1);
this->head_->next_ = temp;
return 0;
@@ -228,7 +240,7 @@ ACE_Unbounded_Stack<T>::pop (T &item)
item = temp->item_;
this->head_->next_ = temp->next_;
- delete temp;
+ this->allocator_->free (temp);
return 0;
}
}
@@ -283,19 +295,24 @@ ACE_Unbounded_Stack<T>::remove (const T &item)
// Skip over the node that we're deleting.
curr->next_ = temp->next_;
this->cur_size_--;
- delete temp;
+ this->allocator_->free (temp);
return 0;
}
}
template <class T>
-ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (void)
+ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (ACE_Allocator *alloc)
: head_ (0),
- cur_size_ (0)
+ cur_size_ (0),
+ allocator_ (alloc)
{
ACE_TRACE ("ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (void)");
- ACE_NEW (this->head_, ACE_Node<T>);
+ if (this->allocator_ == 0)
+ this->allocator_ = ACE_Allocator::instance ();
+
+ ACE_NEW_MALLOC (this->head_, this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T>);
// Make the list circular by pointing it back to itself.
this->head_->next_ = this->head_;
@@ -304,11 +321,16 @@ ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (void)
template <class T>
ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue (const ACE_Unbounded_Queue<T> &us)
: head_ (0),
- cur_size_ (0)
+ cur_size_ (0),
+ allocator_ (us.allocator_)
{
ACE_TRACE ("ACE_Unbounded_Queue<T>::ACE_Unbounded_Queue");
- ACE_NEW (this->head_, ACE_Node<T>);
+ if (this->allocator_ == 0)
+ this->allocator_ = ACE_Allocator::instance ();
+
+ ACE_NEW_MALLOC (this->head_, this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T>);
this->head_->next_ = this->head_;
this->copy_nodes (us);
}
@@ -370,7 +392,7 @@ ACE_Unbounded_Queue<T>::delete_nodes (void)
{
ACE_Node<T> *temp = curr;
curr = curr->next_;
- delete temp;
+ this->allocator_->free (temp);
this->cur_size_--;
}
@@ -384,7 +406,7 @@ ACE_Unbounded_Queue<T>::~ACE_Unbounded_Queue (void)
ACE_TRACE ("ACE_Unbounded_Queue<T>::~ACE_Unbounded_Queue (void)");
this->delete_nodes ();
- delete this->head_;
+ this->allocator_->free (this->head_);
this->head_ = 0;
}
@@ -396,7 +418,8 @@ ACE_Unbounded_Queue<T>::enqueue_head (const T &new_item)
ACE_Node<T> *temp;
// Create a new node that points to the original head.
- ACE_NEW_RETURN (temp, ACE_Node<T> (new_item, this->head_->next_), -1);
+ ACE_NEW_MALLOC_RETURN (temp, this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T> (new_item, this->head_->next_), -1);
// Link this pointer into the front of the list.
this->head_->next_ = temp;
@@ -416,7 +439,8 @@ ACE_Unbounded_Queue<T>::enqueue_tail (const T &new_item)
this->head_->item_ = new_item;
// Create a new dummy node.
- ACE_NEW_RETURN (temp, ACE_Node<T> (this->head_->next_), -1);
+ ACE_NEW_MALLOC_RETURN (temp, this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T> (this->head_->next_), -1);
// Link this dummy pointer into the list.
this->head_->next_ = temp;
@@ -441,7 +465,7 @@ ACE_Unbounded_Queue<T>::dequeue_head (T &item)
item = temp->item_;
this->head_->next_ = temp->next_;
- delete temp;
+ this->allocator_->free (temp);
--this->cur_size_;
return 0;
}
@@ -1033,7 +1057,8 @@ ACE_Unbounded_Set<T>::insert_tail (const T &item)
this->head_->item_ = item;
// Create a new dummy node.
- ACE_NEW_RETURN (temp, ACE_Node<T> (this->head_->next_), -1);
+ ACE_NEW_MALLOC_RETURN (temp, this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T> (this->head_->next_), -1);
// Link this pointer into the list.
this->head_->next_ = temp;
@@ -1086,7 +1111,7 @@ ACE_Unbounded_Set<T>::delete_nodes (void)
{
ACE_Node<T> *temp = curr;
curr = curr->next_;
- delete temp;
+ this->allocator_->free (temp);
this->cur_size_--;
}
@@ -1102,18 +1127,23 @@ ACE_Unbounded_Set<T>::~ACE_Unbounded_Set (void)
this->delete_nodes ();
// Delete the dummy node.
- delete this->head_;
+ this->allocator_->free (this->head_);
this->head_ = 0;
}
template <class T>
-ACE_Unbounded_Set<T>::ACE_Unbounded_Set (void)
+ACE_Unbounded_Set<T>::ACE_Unbounded_Set (ACE_Allocator *alloc)
: head_ (0),
- cur_size_ (0)
+ cur_size_ (0),
+ allocator_ (alloc)
{
// ACE_TRACE ("ACE_Unbounded_Set<T>::ACE_Unbounded_Set");
- ACE_NEW (this->head_, ACE_Node<T>);
+ if (this->allocator_ == 0)
+ this->allocator_ = ACE_Allocator::instance ();
+
+ ACE_MALLOC_NEW (this->head_, this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T>);
// Make the list circular by pointing it back to itself.
this->head_->next_ = this->head_;
@@ -1122,11 +1152,16 @@ ACE_Unbounded_Set<T>::ACE_Unbounded_Set (void)
template <class T>
ACE_Unbounded_Set<T>::ACE_Unbounded_Set (const ACE_Unbounded_Set<T> &us)
: head_ (0),
- cur_size_ (0)
+ cur_size_ (0),
+ allocator_ (us.allocator_)
{
ACE_TRACE ("ACE_Unbounded_Set<T>::ACE_Unbounded_Set");
- ACE_NEW (this->head_, ACE_Node<T>);
+ if (this->allocator_ == 0)
+ this->allocator_ = ACE_Allocator::instance ();
+
+ ACE_MALLOC_NEW (this->head_, this->allocator_->malloc (sizeof (ACE_Node<T>)),
+ ACE_Node<T>);
this->head_->next_ = this->head_;
this->copy_nodes (us);
}
@@ -1192,7 +1227,7 @@ ACE_Unbounded_Set<T>::remove (const T &item)
// Skip over the node that we're deleting.
curr->next_ = temp->next_;
this->cur_size_--;
- delete temp;
+ this->allocator_->free (temp);
return 0;
}
}
diff --git a/ace/Containers.h b/ace/Containers.h
index cffb7258eac..153163c50d3 100644
--- a/ace/Containers.h
+++ b/ace/Containers.h
@@ -18,6 +18,7 @@
#define ACE_CONTAINERS_H
#include "ace/ACE.h"
+#include "ace/Malloc_T.h"
template <class T>
class ACE_Bounded_Stack
@@ -206,8 +207,9 @@ class ACE_Unbounded_Stack
friend class ACE_Unbounded_Stack_Iterator<T>;
public:
// = Initialization, assignemnt, and termination methods.
- ACE_Unbounded_Stack (void);
- // Initialize a new stack so that it is empty.
+ ACE_Unbounded_Stack (ACE_Allocator *alloc = 0);
+ // Initialize a new stack so that it is empty. Use user defined
+ // allocation strategy if specified.
ACE_Unbounded_Stack (const ACE_Unbounded_Stack<T> &s);
// The copy constructor (performs initialization).
@@ -278,6 +280,9 @@ private:
size_t cur_size_;
// Current size of the stack.
+
+ ACE_Allocator *allocator_;
+ // Allocation strategy of the stack.
};
template <class T>
@@ -367,8 +372,9 @@ class ACE_Unbounded_Queue
friend class ACE_Unbounded_Queue_Iterator<T>;
public:
// = Initialization and termination methods.
- ACE_Unbounded_Queue (void);
- // construction.
+ ACE_Unbounded_Queue (ACE_Allocator *alloc = 0);
+ // construction. Use user specified allocation strategy
+ // if specified.
ACE_Unbounded_Queue (const ACE_Unbounded_Queue<T> &);
// Copy constructor.
@@ -437,6 +443,9 @@ protected:
size_t cur_size_;
// Current size of the queue.
+
+ ACE_Allocator *allocator_;
+ // Allocation Strategy of the queue.
};
template <class T>
@@ -488,8 +497,9 @@ class ACE_Unbounded_Set
friend class ACE_Unbounded_Set_Iterator<T>;
public:
// = Initialization and termination methods.
- ACE_Unbounded_Set (void);
- // Constructor.
+ ACE_Unbounded_Set (ACE_Allocator *alloc = 0);
+ // Constructor. Use user specified allocation strategy
+ // if specified.
ACE_Unbounded_Set (const ACE_Unbounded_Set<T> &);
// Copy constructor.
@@ -549,6 +559,9 @@ private:
size_t cur_size_;
// Current size of the set.
+
+ ACE_Allocator *allocator_;
+ // Allocation strategy of the set.
};
// Forward declaration.