summaryrefslogtreecommitdiff
path: root/ace/Containers.cpp
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 /ace/Containers.cpp
parent5fb98cffe19364e1789996e1be200547c525caae (diff)
downloadATCD-756221c7e41280d36898e2c7418c94831d5bf261.tar.gz
Decouple memory allocation strategy for ACE_Unbounded_Stack,
ACE_Unbounded_Set, ACE_Unbounded_Queue.
Diffstat (limited to 'ace/Containers.cpp')
-rw-r--r--ace/Containers.cpp99
1 files changed, 67 insertions, 32 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;
}
}