summaryrefslogtreecommitdiff
path: root/ace
diff options
context:
space:
mode:
Diffstat (limited to 'ace')
-rw-r--r--ace/Obstack.cpp53
-rw-r--r--ace/Obstack.h42
-rw-r--r--ace/Reactor.cpp2
3 files changed, 61 insertions, 36 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_;
}
diff --git a/ace/Obstack.h b/ace/Obstack.h
index d44ef43fa13..a4d253ca3f7 100644
--- a/ace/Obstack.h
+++ b/ace/Obstack.h
@@ -1,7 +1,6 @@
/* -*- C++ -*- */
// $Id$
-
// ============================================================================
//
// = LIBRARY
@@ -18,16 +17,18 @@
#if !defined (ACE_OBSTACK_H)
#define ACE_OBSTACK_H
-#include "ace/ACE.h"
+#include "ace/Malloc.h"
class ACE_Export ACE_Obchunk
{
// = TITLE
- // A "chunk" of memory. This should be a nested class but some
- // compilers don't like them yet.
-friend class ACE_Obstack;
-
+ // Defines the state that represents a "chunk" of memory.
public:
+ friend class ACE_Obstack;
+
+ ACE_Obchunk (size_t size);
+ // Constructor.
+
void dump (void) const;
// Dump the state of an object.
@@ -36,26 +37,41 @@ public:
private:
char *end_;
+ // Pointer to the end of the chunk.
+
char *cur_;
+ // Pointer to the current location in the chunk.
+
ACE_Obchunk *next_;
+ // Next chunk in the chain.
+
char contents_[4];
+ // Pointer to the beginning contents of this chunk. This field is
+ // actually overlayed by the memory allocated by
+ // <ACE_Obstack::new_chunk>. Therefore, it *must* come last.
};
class ACE_Export ACE_Obstack
{
// = TITLE
- // Define a simple "mark and release" memory allocation utility.
- // This class is based on the GNU obstack utility.
+ // Define a simple "mark and release" memory allocation utility.
+ //
+ // = DESCRIPTION
+ // The implementation is similar to the GNU obstack utility,
+ // which is used extensively in the GCC compiler.
public:
// = Initialization and termination methods.
- ACE_Obstack (int size = 4080);
+ ACE_Obstack (size_t size = 4096 - sizeof (ACE_Obchunk),
+ ACE_Allocator *allocator_strategy = 0);
~ACE_Obstack (void);
- char *copy (const char* data, size_t len);
+ char *copy (const char *data,
+ size_t len);
// Copy the data into the current Obchunk.
void release (void);
- // "Release" the entire stack (without freeing it).
+ // "Release" the entire stack of Obchunks, putting it back on the
+ // free list.
void dump (void) const;
// Dump the state of an object.
@@ -66,9 +82,13 @@ public:
protected:
class ACE_Obchunk *new_chunk (void);
+ ACE_Allocator *allocator_strategy_;
+ // Pointer to the allocator used by this Obstack.
+
size_t size_;
// Current size of the Obstack;
+ // = Don't change the order of the following two fields.
class ACE_Obchunk *head_;
// Head of the Obchunk chain.
diff --git a/ace/Reactor.cpp b/ace/Reactor.cpp
index 6cc6340ab49..ec4eed0fee5 100644
--- a/ace/Reactor.cpp
+++ b/ace/Reactor.cpp
@@ -1,9 +1,7 @@
// $Id$
#define ACE_BUILD_DLL
-
#include "ace/Reactor.h"
-
#include "ace/Reactor_Impl.h"
#include "ace/Handle_Set.h"
#include "ace/Service_Config.h"