#include <Malloc_Base.h>
Inheritance diagram for ACE_Allocator:
Public Types | |
typedef size_t | size_type |
Unsigned integer type used for specifying memory block lengths. | |
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_type nbytes)=0 |
Allocate nbytes, but don't give them any initial value. | |
virtual void * | calloc (size_type nbytes, char initial_value= '\0')=0 |
Allocate nbytes, giving them initial_value. | |
virtual void * | calloc (size_type n_elem, size_type elem_size, char initial_value= '\0')=0 |
virtual void | free (void *ptr)=0 |
Free <ptr> (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_type len, int flags=MS_SYNC)=0 |
virtual int | protect (ssize_t len=-1, int prot=PROT_RDWR)=0 |
virtual int | protect (void *addr, size_type len, int prot=PROT_RDWR)=0 |
virtual void | dump (void) const =0 |
Dump the state of the object. | |
Static Public Member Functions | |
static ACE_Allocator * | instance (void) |
Get pointer to a default ACE_Allocator. | |
static ACE_Allocator * | instance (ACE_Allocator *) |
static void | close_singleton (void) |
Delete the dynamically allocated Singleton. | |
Static Private Attributes | |
static ACE_Allocator * | allocator_ = 0 |
Pointer to a process-wide ACE_Allocator instance. | |
static int | delete_allocator_ = 0 |
Must delete the <allocator_> if non-0. |
Definition at line 39 of file Malloc_Base.h.
typedef size_t ACE_Allocator::size_type |
Unsigned integer type used for specifying memory block lengths.
Definition at line 44 of file Malloc_Base.h.
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 }
virtual int ACE_Allocator::bind | ( | const char * | name, | |
void * | pointer, | |||
int | duplicates = 0 | |||
) | [pure virtual] |
Associate name with pointer. If duplicates == 0 then do not allow duplicate name/pointer associations, else if duplicates != 0 then allow duplicate name/pointer assocations. Returns 0 if successfully binds (1) a previously unbound name or (2) duplicates != 0, returns 1 if trying to bind a previously bound name and duplicates == 0, else returns -1 if a resource failure occurs.
Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, and ACE_Allocator_Adapter< MALLOC >.
virtual void* ACE_Allocator::calloc | ( | size_type | n_elem, | |
size_type | elem_size, | |||
char | initial_value = '\0' | |||
) | [pure virtual] |
Allocate <n_elem> each of size elem_size, giving them initial_value.
Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Cached_Allocator< T, ACE_LOCK >, ACE_Dynamic_Cached_Allocator< ACE_LOCK >, and ACE_Allocator_Adapter< MALLOC >.
virtual void* ACE_Allocator::calloc | ( | size_type | nbytes, | |
char | initial_value = '\0' | |||
) | [pure virtual] |
Allocate nbytes, giving them initial_value.
Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, ACE_Cached_Allocator< T, ACE_LOCK >, ACE_Dynamic_Cached_Allocator< ACE_LOCK >, and ACE_Allocator_Adapter< MALLOC >.
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, and ACE_Allocator_Adapter< MALLOC >.
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(), ACE_Hash_Multi_Map_Manager< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, 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, and ACE_Allocator_Adapter< MALLOC >.
virtual int ACE_Allocator::find | ( | const char * | name, | |
void *& | pointer | |||
) | [pure virtual] |
Locate name and pass out parameter via pointer. If found, return 0, returns -1 if failure occurs.
Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, and ACE_Allocator_Adapter< MALLOC >.
virtual void ACE_Allocator::free | ( | void * | ptr | ) | [pure virtual] |
Free <ptr> (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 >, and ACE_Allocator_Adapter< MALLOC >.
Referenced by ACE_Configuration_Heap::add_section(), ACE_Data_Block::base(), ACE_String_Base< CHAR >::clear(), ACE_Data_Block::clone_nocopy(), ACE_Hash_Multi_Map_Manager< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::close_i(), ACE_Hash_Map_Manager_Ex< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, ACE_LOCK >::close_i(), ACE_String_Base< CHAR >::fast_resize(), 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_Message_Block::init_i(), ACE_Configuration_Heap::new_section(), ACE_SString::operator=(), ACE_Message_Block::release(), ACE_Data_Block::release(), ACE_Message_Block::release_i(), 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_Data_Block::ACE_Data_Block(), ACE_Double_Linked_List< T >::ACE_Double_Linked_List(), ACE_Obstack_T< CHAR >::ACE_Obstack_T(), 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_Ex< T, C >::ACE_Unbounded_Set_Ex(), ACE_Unbounded_Stack< T >::ACE_Unbounded_Stack(), ACE_Message_Block::init_i(), ACE_RB_Tree< EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK >::open(), ACE_Map_Manager< EXT_ID, INT_ID, ACE_LOCK >::open(), ACE_Hash_Multi_Map_Manager< EXT_ID, INT_ID, HASH_KEY, COMPARE_KEYS, 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_type | nbytes | ) | [pure virtual] |
Allocate nbytes, 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 >, and ACE_Allocator_Adapter< MALLOC >.
Referenced by ACE_Configuration_Heap::add_section(), ACE_Message_Block::clone(), ACE_Configuration_Heap::create_index(), ACE_Message_Block::duplicate(), ACE_String_Base< CHAR >::fast_resize(), ACE_Message_Block::init_i(), ACE_Configuration_Heap::new_section(), 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_type | len, | |||
int | prot = PROT_RDWR | |||
) | [pure virtual] |
Change the protection of the pages of the mapped region to prot starting at addr up to len bytes.
Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, and ACE_Allocator_Adapter< MALLOC >.
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 prot starting at <this->base_addr_> up to len bytes. If len == -1 then change protection of all pages in the mapped region.
Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, and ACE_Allocator_Adapter< MALLOC >.
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, and ACE_Allocator_Adapter< MALLOC >.
Referenced by ACE_Configuration_Heap::create_index().
virtual int ACE_Allocator::sync | ( | void * | addr, | |
size_type | 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, and ACE_Allocator_Adapter< MALLOC >.
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, and ACE_Allocator_Adapter< MALLOC >.
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 name with pointer. Does not allow duplicate name/pointer associations. Returns 0 if successfully binds (1) a previously unbound name, 1 if trying to bind a previously bound name, or returns -1 if a resource failure occurs. When this call returns pointer's value will always reference the void * that name is associated with. Thus, if the caller needs to use pointer (e.g., to free it) a copy must be maintained by the caller.
Implemented in ACE_New_Allocator, ACE_Static_Allocator_Base, and ACE_Allocator_Adapter< MALLOC >.
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, and ACE_Allocator_Adapter< MALLOC >.
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, and ACE_Allocator_Adapter< MALLOC >.
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 >.
Definition at line 159 of file Malloc_Base.h.
Referenced by close_singleton(), and instance().
int ACE_Allocator::delete_allocator_ = 0 [static, private] |
Must delete the <allocator_> if non-0.
Definition at line 162 of file Malloc_Base.h.
Referenced by close_singleton(), and instance().