ACE_Allocator Class Reference

Interface for a dynamic memory allocator that uses inheritance and dynamic binding to provide extensible mechanisms for allocating and deallocating memory. More...

#include <Malloc_Base.h>

Inheritance diagram for ACE_Allocator:

Inheritance graph
[legend]
Collaboration diagram for ACE_Allocator:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ACE_Allocator (void)
 "No-op" constructor (needed to make certain compilers happy).

virtual ~ACE_Allocator (void)
 Virtual destructor.

virtual void * malloc (size_t nbytes)=0
 Allocate , but don't give them any initial value.

virtual void * calloc (size_t nbytes, char initial_value= '\0')=0
 Allocate , giving them .

virtual void * calloc (size_t n_elem, size_t elem_size, char initial_value= '\0')=0
virtual void free (void *ptr)=0
 Free (must have been allocated by <ACE_Allocator::malloc>).

virtual int remove (void)=0
 Remove any resources associated with this memory manager.

virtual int bind (const char *name, void *pointer, int duplicates=0)=0
virtual int trybind (const char *name, void *&pointer)=0
virtual int find (const char *name, void *&pointer)=0
virtual int find (const char *name)=0
 Returns 0 if the name is in the mapping. -1, otherwise.

virtual int unbind (const char *name)=0
virtual int unbind (const char *name, void *&pointer)=0
virtual int sync (ssize_t len=-1, int flags=MS_SYNC)=0
virtual int sync (void *addr, size_t len, int flags=MS_SYNC)=0
virtual int protect (ssize_t len=-1, int prot=PROT_RDWR)=0
virtual int protect (void *addr, size_t len, int prot=PROT_RDWR)=0
virtual void dump (void) const=0
 Dump the state of the object.


Static Public Member Functions

ACE_Allocatorinstance (void)
 Get pointer to a default ACE_Allocator.

ACE_Allocatorinstance (ACE_Allocator *)
void close_singleton (void)
 Delete the dynamically allocated Singleton.


Static Private Attributes

ACE_Allocatorallocator_ = 0
 Pointer to a process-wide ACE_Allocator instance.

int delete_allocator_ = 0
 Must delete the if non-0.


Detailed Description

Interface for a dynamic memory allocator that uses inheritance and dynamic binding to provide extensible mechanisms for allocating and deallocating memory.

Definition at line 39 of file Malloc_Base.h.


Constructor & Destructor Documentation

ACE_Allocator::ACE_Allocator void   ) 
 

"No-op" constructor (needed to make certain compilers happy).

Definition at line 105 of file Malloc_Allocator.cpp.

References ACE_TRACE.

00106 {
00107   ACE_TRACE ("ACE_Allocator::ACE_Allocator");
00108 }

ACE_Allocator::~ACE_Allocator void   )  [virtual]
 

Virtual destructor.

Definition at line 100 of file Malloc_Allocator.cpp.

References ACE_TRACE.

00101 {
00102   ACE_TRACE ("ACE_Allocator::~ACE_Allocator");
00103 }


Member Function Documentation

virtual int ACE_Allocator::bind const char *  name,
void *  pointer,
int  duplicates = 0
[pure virtual]
 

Associate with . If == 0 then do not allow duplicate / associations, else if != 0 then allow duplicate / assocations. Returns 0 if successfully binds (1) a previously unbound or (2) != 0, returns 1 if trying to bind a previously bound and == 0, else returns -1 if a resource failure occurs.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

Referenced by ACE_Configuration_Heap::create_index().

virtual void* ACE_Allocator::calloc size_t  n_elem,
size_t  elem_size,
char  initial_value = '\0'
[pure virtual]
 

Allocate each of size , giving them .

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Cached_Allocator< T, ACE_LOCK >, ACE_Dynamic_Cached_Allocator< ACE_LOCK >, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

virtual void* ACE_Allocator::calloc size_t  nbytes,
char  initial_value = '\0'
[pure virtual]
 

Allocate , giving them .

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Cached_Allocator< T, ACE_LOCK >, ACE_Dynamic_Cached_Allocator< ACE_LOCK >, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

void ACE_Allocator::close_singleton void   )  [static]
 

Delete the dynamically allocated Singleton.

Definition at line 83 of file Malloc_Allocator.cpp.

References ACE_GUARD, ACE_TRACE, allocator_, and delete_allocator_.

Referenced by ACE_Object_Manager::fini().

00084 {
00085   ACE_TRACE ("ACE_Allocator::close_singleton");
00086 
00087   ACE_MT (ACE_GUARD (ACE_Recursive_Thread_Mutex, ace_mon,
00088                      *ACE_Static_Object_Lock::instance ()));
00089 
00090   if (ACE_Allocator::delete_allocator_)
00091     {
00092       // This should never be executed....  See the
00093       // ACE_Allocator::instance (void) method for an explanation.
00094       delete ACE_Allocator::allocator_;
00095       ACE_Allocator::allocator_ = 0;
00096       ACE_Allocator::delete_allocator_ = 0;
00097     }
00098 }

virtual void ACE_Allocator::dump void   )  const [pure virtual]
 

Dump the state of the object.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

Referenced by ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::dump(), ACE_Data_Block::dump(), ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::dump(), and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::dump().

virtual int ACE_Allocator::find const char *  name  )  [pure virtual]
 

Returns 0 if the name is in the mapping. -1, otherwise.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

virtual int ACE_Allocator::find const char *  name,
void *&  pointer
[pure virtual]
 

Locate and pass out parameter via pointer. If found, return 0, returns -1 if failure occurs.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

Referenced by ACE_Configuration_Heap::create_index().

virtual void ACE_Allocator::free void *  ptr  )  [pure virtual]
 

Free (must have been allocated by <ACE_Allocator::malloc>).

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Cached_Allocator< T, ACE_LOCK >, ACE_Dynamic_Cached_Allocator< ACE_LOCK >, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

Referenced by ACE_Configuration_Heap::add_section(), ACE_String_Base< CHAR >::append(), ACE_Data_Block::base(), ACE_String_Base< CHAR >::clear(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::close_i(), ACE_Configuration_Section_IntId::free(), ACE_Configuration_ExtId::free(), ACE_Configuration_Value_IntId::free(), ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::free_search_structure(), ACE_Configuration_Heap::new_section(), ACE_SString::operator=(), ACE_Message_Block::release(), ACE_Data_Block::release(), ACE_Message_Block::release_i(), ACE_String_Base< CHAR >::resize(), ACE_String_Base< CHAR >::set(), ACE_Configuration_Heap::set_binary_value(), ACE_Configuration_Heap::set_integer_value(), ACE_Configuration_Heap::set_string_value(), ACE_Data_Block::size(), ACE_Data_Block::~ACE_Data_Block(), ACE_Obstack_T< CHAR >::~ACE_Obstack_T(), and ACE_String_Base< CHAR >::~ACE_String_Base().

ACE_Allocator * ACE_Allocator::instance ACE_Allocator  )  [static]
 

Set pointer to a process-wide ACE_Allocator and return existing pointer.

Definition at line 68 of file Malloc_Allocator.cpp.

References ACE_GUARD_RETURN, ACE_TRACE, allocator_, and delete_allocator_.

00069 {
00070   ACE_TRACE ("ACE_Allocator::instance");
00071   ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00072                             *ACE_Static_Object_Lock::instance (), 0));
00073   ACE_Allocator *t = ACE_Allocator::allocator_;
00074 
00075   // We can't safely delete it since we don't know who created it!
00076   ACE_Allocator::delete_allocator_ = 0;
00077 
00078   ACE_Allocator::allocator_ = r;
00079   return t;
00080 }

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_Allocator * ACE_Allocator::instance void   )  [static]
 

Get pointer to a default ACE_Allocator.

Definition at line 20 of file Malloc_Allocator.cpp.

References ACE_ASSERT, ACE_GUARD_RETURN, and allocator_.

Referenced by ACE_Activation_Queue::ACE_Activation_Queue(), ACE_Array_Base< T >::ACE_Array_Base(), ACE_Double_Linked_List< T >::ACE_Double_Linked_List(), ACE_Ordered_MultiSet< T >::ACE_Ordered_MultiSet(), ACE_Read_Buffer::ACE_Read_Buffer(), ACE_SString::ACE_SString(), ACE_Unbounded_Queue< T >::ACE_Unbounded_Queue(), ACE_Unbounded_Set< T >::ACE_Unbounded_Set(), ACE_Unbounded_Stack< T >::ACE_Unbounded_Stack(), ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::open(), ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::open(), and ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::open().

00021 {
00022   //  ACE_TRACE ("ACE_Allocator::instance");
00023 
00024   if (ACE_Allocator::allocator_ == 0)
00025     {
00026       // Perform Double-Checked Locking Optimization.
00027       ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon,
00028                                 *ACE_Static_Object_Lock::instance (), 0));
00029 
00030       if (ACE_Allocator::allocator_ == 0)
00031         {
00032           // Have a seat.  We want to avoid ever having to delete the
00033           // ACE_Allocator instance, to avoid shutdown order
00034           // dependencies.  ACE_New_Allocator never needs to be
00035           // destroyed:  its destructor is empty and its instance
00036           // doesn't have any state.  Therefore, sizeof
00037           // ACE_New_Allocator is equal to sizeof void *.  It's
00038           // instance just contains a pointer to its virtual function
00039           // table.
00040           //
00041           // So, we allocate space for the ACE_New_Allocator instance
00042           // in the data segment.  Because its size is the same as
00043           // that of a pointer, we allocate it as a pointer so that it
00044           // doesn't get constructed statically.  We never bother to
00045           // destroy it.
00046           static void *allocator_instance = 0;
00047 
00048           // Check this critical assumption.  We put it in a variable
00049           // first to avoid stupid compiler warnings that the
00050           // condition may always be true/false.
00051 #         if !defined (ACE_NDEBUG)
00052           int assertion = (sizeof allocator_instance ==
00053                            sizeof (ACE_New_Allocator));
00054           ACE_ASSERT (assertion);
00055 #         endif /* !ACE_NDEBUG */
00056 
00057           // Initialize the allocator_instance by using a placement
00058           // new.
00059           ACE_Allocator::allocator_ =
00060             new (&allocator_instance) ACE_New_Allocator;
00061         }
00062     }
00063 
00064   return ACE_Allocator::allocator_;
00065 }

virtual void* ACE_Allocator::malloc size_t  nbytes  )  [pure virtual]
 

Allocate , but don't give them any initial value.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Cached_Allocator< T, ACE_LOCK >, ACE_Dynamic_Cached_Allocator< ACE_LOCK >, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

Referenced by ACE_SString::ACE_SString(), ACE_Configuration_Heap::add_section(), ACE_Message_Block::clone(), ACE_Configuration_Heap::create_index(), ACE_Message_Block::duplicate(), ACE_Message_Block::init_i(), ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::insert_i(), ACE_Configuration_Heap::new_section(), ACE_SString::operator=(), ACE_Read_Buffer::rec_read(), ACE_String_Base< CHAR >::resize(), ACE_Configuration_Heap::set_binary_value(), ACE_Configuration_Heap::set_integer_value(), and ACE_Configuration_Heap::set_string_value().

virtual int ACE_Allocator::protect void *  addr,
size_t  len,
int  prot = PROT_RDWR
[pure virtual]
 

Change the protection of the pages of the mapped region to starting at up to bytes.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

virtual int ACE_Allocator::protect ssize_t  len = -1,
int  prot = PROT_RDWR
[pure virtual]
 

Change the protection of the pages of the mapped region to starting at <this->base_addr_> up to bytes. If == -1 then change protection of all pages in the mapped region.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

virtual int ACE_Allocator::remove void   )  [pure virtual]
 

Remove any resources associated with this memory manager.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

Referenced by ACE_Configuration_Heap::create_index().

virtual int ACE_Allocator::sync void *  addr,
size_t  len,
int  flags = MS_SYNC
[pure virtual]
 

Sync len bytes of the memory region to the backing store starting at addr.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

virtual int ACE_Allocator::sync ssize_t  len = -1,
int  flags = MS_SYNC
[pure virtual]
 

Sync len bytes of the memory region to the backing store starting at this->base_addr_. If len == -1 then sync the whole region.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

Referenced by ACE_Configuration_Heap::new_section(), ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::rebind_i(), and ACE_Configuration_Heap::~ACE_Configuration_Heap().

virtual int ACE_Allocator::trybind const char *  name,
void *&  pointer
[pure virtual]
 

Associate with . Does not allow duplicate / associations. Returns 0 if successfully binds (1) a previously unbound , 1 if trying to bind a previously bound , or returns -1 if a resource failure occurs. When this call returns 's value will always reference the void * that is associated with. Thus, if the caller needs to use (e.g., to free it) a copy must be maintained by the caller.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

virtual int ACE_Allocator::unbind const char *  name,
void *&  pointer
[pure virtual]
 

Break any association of name. Returns the value of pointer in case the caller needs to deallocate memory.

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

virtual int ACE_Allocator::unbind const char *  name  )  [pure virtual]
 

Unbind (remove) the name from the map. Don't return the pointer to the caller

Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.


Member Data Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_Allocator * ACE_Allocator::allocator_ = 0 [static, private]
 

Pointer to a process-wide ACE_Allocator instance.

Reimplemented in ACE_Allocator_Adapter< MALLOC >, and ACE_Allocator_Adapter< ACE_Malloc< ACE_MEM_POOL_2, ACE_LOCK > >.

Definition at line 22 of file Malloc.cpp.

Referenced by close_singleton(), and instance().

int ACE_Allocator::delete_allocator_ = 0 [static, private]
 

Must delete the if non-0.

Definition at line 27 of file Malloc.cpp.

Referenced by close_singleton(), and instance().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 11:19:11 2006 for ACE by doxygen 1.3.6