OpenDDS
Snapshot(2023/04/07-19:43)
|
A size-based allocator that caches blocks for quicker access, but if the pool is exhausted it will use the heap. More...
#include <Dynamic_Cached_Allocator_With_Overflow_T.h>
Public Member Functions | |
Dynamic_Cached_Allocator_With_Overflow (size_t n_chunks, size_t chunk_size) | |
~Dynamic_Cached_Allocator_With_Overflow () | |
Clear things up. More... | |
void * | malloc (size_t nbytes=0) |
virtual void * | calloc (size_t, char='\0') |
virtual void * | calloc (size_t, size_t, char='\0') |
void | free (void *ptr) |
Return a chunk of memory back to free list cache. More... | |
size_t | pool_depth () |
Return the number of chunks available in the cache. More... | |
size_t | available () |
![]() | |
virtual int | remove (void) |
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) |
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 |
![]() | |
ACE_Allocator (void) | |
virtual | ~ACE_Allocator (void) |
Public Attributes | |
Atomic< unsigned long > | allocs_from_heap_ |
number of allocations from the heap. More... | |
Atomic< unsigned long > | allocs_from_pool_ |
number of allocations from the pool. More... | |
Atomic< unsigned long > | frees_to_heap_ |
number of frees returned to the heap More... | |
Atomic< unsigned long > | frees_to_pool_ |
number of frees returned to the pool More... | |
Private Attributes | |
unsigned char * | begin_ |
unsigned char * | end_ |
The end of the pool. More... | |
ACE_Locked_Free_List< ACE_Cached_Mem_Pool_Node< char >, ACE_LOCK > | free_list_ |
size_t | chunk_size_ |
Remember the size of our chunks. More... | |
Additional Inherited Members | |
![]() | |
typedef size_t | size_type |
![]() | |
static ACE_Allocator * | instance (void) |
static ACE_Allocator * | instance (ACE_Allocator *) |
static void | close_singleton (void) |
A size-based allocator that caches blocks for quicker access, but if the pool is exhausted it will use the heap.
This class enables caching of dynamically allocated, fixed-size chunks. Notice that the chunk_size
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 and ACE_Process_Mutex constructor API.
Definition at line 45 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
|
inline |
Create a cached memory pool with n_chunks chunks each with chunk_size size.
Definition at line 49 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
|
inline |
Clear things up.
Definition at line 73 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
|
inline |
How many chunks are available at this time.
Definition at line 212 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::free(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::malloc().
|
inlinevirtual |
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 chunk_size, and is otherwise ignored since calloc() always returns a pointer to an item of chunk_size.
Reimplemented from ACE_New_Allocator.
Definition at line 137 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
|
inlinevirtual |
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.
Definition at line 144 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
|
inlinevirtual |
Return a chunk of memory back to free list cache.
Reimplemented from ACE_New_Allocator.
Definition at line 151 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
|
inlinevirtual |
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 chunk_size, and is otherwise ignored since malloc() always returns a pointer to an item of chunk_size size.
Reimplemented from ACE_New_Allocator.
Definition at line 85 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
|
inline |
Return the number of chunks available in the cache.
Definition at line 204 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Atomic<unsigned long> OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::allocs_from_heap_ |
number of allocations from the heap.
Definition at line 214 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::free(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::malloc().
Atomic<unsigned long> OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::allocs_from_pool_ |
number of allocations from the pool.
Definition at line 219 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::free(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::malloc().
|
private |
Remember how we allocate the memory in the first place so we can clear things up later.
Definition at line 227 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::Dynamic_Cached_Allocator_With_Overflow(), OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::free(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::~Dynamic_Cached_Allocator_With_Overflow().
|
private |
Remember the size of our chunks.
Definition at line 238 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::Dynamic_Cached_Allocator_With_Overflow(), OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::malloc(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::~Dynamic_Cached_Allocator_With_Overflow().
|
private |
The end of the pool.
Definition at line 229 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::Dynamic_Cached_Allocator_With_Overflow(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::free().
|
private |
Maintain a cached memory free list. We use char
as template parameter, although sizeof(char) is usually less than sizeof(void*). Really important is that chunk_size must be greater or equal to sizeof(void*).
Definition at line 235 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::available(), OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::Dynamic_Cached_Allocator_With_Overflow(), OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::free(), OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::malloc(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::pool_depth().
Atomic<unsigned long> OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::frees_to_heap_ |
number of frees returned to the heap
Definition at line 221 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::free(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::malloc().
Atomic<unsigned long> OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::frees_to_pool_ |
number of frees returned to the pool
Definition at line 223 of file Dynamic_Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::free(), and OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_Thread_Mutex >::malloc().