summaryrefslogtreecommitdiff
path: root/ace/Obstack.cpp
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1997-12-30 21:59:57 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1997-12-30 21:59:57 +0000
commit40e4df5e8d19f09c8aea265a007dc054914ef959 (patch)
tree626016e4f016dc4ced17655c496751dc2137a03a /ace/Obstack.cpp
parent583be1059139ffec7bb6186e07f30b816d98a11d (diff)
downloadATCD-40e4df5e8d19f09c8aea265a007dc054914ef959.tar.gz
*** empty log message ***
Diffstat (limited to 'ace/Obstack.cpp')
-rw-r--r--ace/Obstack.cpp53
1 files changed, 30 insertions, 23 deletions
diff --git a/ace/Obstack.cpp b/ace/Obstack.cpp
index 5bd969201bb..7ad85ee68aa 100644
--- a/ace/Obstack.cpp
+++ b/ace/Obstack.cpp
@@ -1,4 +1,3 @@
-// Obstack.cpp
// $Id$
#define ACE_BUILD_DLL
@@ -31,45 +30,52 @@ ACE_Obchunk::dump (void) const
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
+ACE_Obchunk::ACE_Obchunk (size_t size)
+ : end_ (contents_ + size),
+ cur_ (contents_),
+ next_ (0)
+{
+}
+
class ACE_Obchunk *
ACE_Obstack::new_chunk (void)
{
ACE_TRACE ("ACE_Obstack::new_chunk");
- class ACE_Obchunk *temp = (class ACE_Obchunk *)
- new char[sizeof (class ACE_Obchunk) + this->size_];
-
- if (temp == 0)
- {
- errno = ENOMEM;
- return 0;
- }
- temp->next_ = 0;
- temp->end_ = temp->contents_ + this->size_;
- temp->cur_ = temp->contents_;
+ char *temp;
+
+ ACE_ALLOCATOR_RETURN (temp,
+ (char *) this->allocator_strategy_->malloc (sizeof (class ACE_Obchunk) + this->size_),
+ 0);
- return temp;
+ return new (temp) ACE_Obchunk (this->size_);
}
-ACE_Obstack::ACE_Obstack (int sz)
- : size_ (sz),
- head_ (0)
+ACE_Obstack::ACE_Obstack (size_t size,
+ ACE_Allocator *allocator_strategy)
+ : allocator_strategy_ (allocator_strategy),
+ size_ (size),
+ head_ (this->new_chunk ()),
+ curr_ (head_)
{
ACE_TRACE ("ACE_Obstack::ACE_Obstack");
- this->head_ = this->new_chunk ();
- this->curr_ = this->head_;
+
+ if (this->allocator_strategy_ == 0)
+ ACE_ALLOCATOR (this->allocator_strategy_,
+ ACE_Allocator::instance ());
}
ACE_Obstack::~ACE_Obstack (void)
{
ACE_TRACE ("ACE_Obstack::~ACE_Obstack");
- class ACE_Obchunk *temp = this->head_;
+
+ ACE_Obchunk *temp = this->head_;
while (temp != 0)
{
- class ACE_Obchunk *next = temp->next_;
+ ACE_Obchunk *next = temp->next_;
temp->next_ = 0;
- delete [] temp;
+ this->allocator_strategy_->free ((void *) temp);
temp = next;
}
}
@@ -87,15 +93,15 @@ ACE_Obstack::copy (const char *s,
if (this->curr_->cur_ + len + 1 >= this->curr_->end_)
{
- // Check whether we can just reuse previously allocated memory.
-
if (this->curr_->next_ == 0)
{
+ // We must allocate new memory.
this->curr_->next_ = this->new_chunk ();
this->curr_ = this->curr_->next_;
}
else
{
+ // We can reuse previously allocated memory.
this->curr_ = this->curr_->next_;
this->curr_->cur_ = this->curr_->contents_;
}
@@ -112,6 +118,7 @@ void
ACE_Obstack::release (void)
{
ACE_TRACE ("ACE_Obstack::release");
+
this->curr_ = this->head_;
this->curr_->cur_ = this->curr_->contents_;
}