ACE
6.1.8
|
A fixed-size allocator that caches items for quicker access. More...
#include <Malloc_T.h>
Public Member Functions | |
ACE_Cached_Allocator (size_t n_chunks) | |
~ACE_Cached_Allocator (void) | |
Clear things up. More... | |
void * | malloc (size_t nbytes=sizeof(T)) |
virtual void * | calloc (size_t nbytes, char initial_value= '\0') |
virtual void * | calloc (size_t n_elem, size_t elem_size, char initial_value= '\0') |
void | free (void *) |
Return a chunk of memory back to free list cache. More... | |
size_t | pool_depth (void) |
Return the number of chunks available in the cache. More... | |
![]() | |
virtual int | remove (void) |
These methods are no-ops. More... | |
virtual int | bind (const char *name, void *pointer, int duplicates=0) |
virtual int | trybind (const char *name, void *&pointer) |
virtual int | find (const char *name, void *&pointer) |
virtual int | find (const char *name) |
Returns 0 if the name is in the mapping. -1, otherwise. More... | |
virtual int | unbind (const char *name) |
virtual int | unbind (const char *name, void *&pointer) |
virtual int | sync (ssize_t len=-1, int flags=MS_SYNC) |
virtual int | sync (void *addr, size_t len, int flags=MS_SYNC) |
virtual int | protect (ssize_t len=-1, int prot=PROT_RDWR) |
virtual int | protect (void *addr, size_t len, int prot=PROT_RDWR) |
virtual void | dump (void) const |
Dump the state of the object. More... | |
![]() | |
ACE_Allocator (void) | |
"No-op" constructor (needed to make certain compilers happy). More... | |
virtual | ~ACE_Allocator (void) |
Virtual destructor. More... | |
Private Attributes | |
char * | pool_ |
ACE_Locked_Free_List < ACE_Cached_Mem_Pool_Node< T > , ACE_LOCK > | free_list_ |
Maintain a cached memory free list. More... | |
Additional Inherited Members | |
![]() | |
typedef size_t | size_type |
Unsigned integer type used for specifying memory block lengths. More... | |
![]() | |
static ACE_Allocator * | instance (void) |
Get pointer to a default ACE_Allocator. More... | |
static ACE_Allocator * | instance (ACE_Allocator *) |
static void | close_singleton (void) |
Delete the dynamically allocated Singleton. More... | |
A fixed-size allocator that caches items for quicker access.
This class enables caching of dynamically allocated, fixed-sized classes. Notice that the sizeof (TYPE)
must be greater than or equal to sizeof (void*)
for this to work properly.
This class can be configured flexibly with different types of ACE_LOCK strategies that support the ACE_Thread_Mutex, ACE_Thread_Semaphore, ACE_Process_Mutex, and ACE_Process_Semaphore constructor API.
ACE_Cached_Allocator< T, ACE_LOCK >::ACE_Cached_Allocator | ( | size_t | n_chunks | ) |
Create a cached memory pool with n_chunks chunks each with sizeof (TYPE) size.
ACE_Cached_Allocator< T, ACE_LOCK >::~ACE_Cached_Allocator | ( | void | ) |
Clear things up.
|
virtual |
Get a chunk of memory from free list cache, giving them initial_value. Note that nbytes is only checked to make sure that it's less or equal to sizeof T, and is otherwise ignored since calloc() always returns a pointer to an item of sizeof (T).
Reimplemented from ACE_New_Allocator.
|
virtual |
This method is a no-op and just returns 0 since the free list only works with fixed sized entities.
Reimplemented from ACE_New_Allocator.
|
virtual |
Return a chunk of memory back to free list cache.
Reimplemented from ACE_New_Allocator.
|
virtual |
Get a chunk of memory from free list cache. Note that nbytes is only checked to make sure that it's less or equal to sizeof T, and is otherwise ignored since malloc()
always returns a pointer to an item of sizeof (T).
Reimplemented from ACE_New_Allocator.
|
inline |
Return the number of chunks available in the cache.
|
private |
Maintain a cached memory free list.
|
private |
Remember how we allocate the memory in the first place so we can clear things up later.