diff options
author | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-07-29 18:15:04 +0000 |
---|---|---|
committer | nw1 <nw1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-07-29 18:15:04 +0000 |
commit | f54306acd856dfec36606fff1de280f1e888460a (patch) | |
tree | 62afe8e8c0900b0213b3cc48d6bd052e0b944014 /ace/Containers.cpp | |
parent | 241e2af6f8351fdc19d3b6192fdae987b461f2e3 (diff) | |
download | ATCD-f54306acd856dfec36606fff1de280f1e888460a.tar.gz |
Added back parameterized allocation strategy version.
Diffstat (limited to 'ace/Containers.cpp')
-rw-r--r-- | ace/Containers.cpp | 111 |
1 files changed, 79 insertions, 32 deletions
diff --git a/ace/Containers.cpp b/ace/Containers.cpp index 8b799150e42..0d7c2d0808d 100644 --- a/ace/Containers.cpp +++ b/ace/Containers.cpp @@ -5,6 +5,8 @@ #define ACE_CONTAINERS_C #define ACE_BUILD_DLL + +#include "ace/Malloc.h" #include "ace/Containers.h" #if !defined (__ACE_INLINE__) @@ -127,13 +129,19 @@ 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_, + (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + ACE_Node<T>); + this->head_->next_ = this->head_; } template<class T> void @@ -145,7 +153,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 +173,24 @@ 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_, + (ACE_Node<T>*) 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_, + (ACE_Node<T>*) 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 +214,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 +224,9 @@ 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, + (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + ACE_Node<T> (new_item, this->head_->next_), -1); this->head_->next_ = temp; return 0; @@ -228,7 +245,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 +300,25 @@ 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_, + (ACE_Node<T>*) 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 +327,17 @@ 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_, + (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + ACE_Node<T>); this->head_->next_ = this->head_; this->copy_nodes (us); } @@ -370,7 +399,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 +413,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 +425,9 @@ 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, + (ACE_Node<T>*) 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 +447,9 @@ 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, + (ACE_Node<T>*) 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 +474,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 +1066,9 @@ 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, + (ACE_Node<T>*) 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 +1121,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 +1137,24 @@ 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_NEW_MALLOC (this->head_, + (ACE_Node<T>*) 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 +1163,17 @@ 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_NEW_MALLOC (this->head_, + (ACE_Node<T>*) this->allocator_->malloc (sizeof (ACE_Node<T>)), + ACE_Node<T>); this->head_->next_ = this->head_; this->copy_nodes (us); } @@ -1192,7 +1239,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; } } |