OpenDDS
Snapshot(2023/04/07-19:43)
|
A fixed-size allocator that caches items for quicker access but if the pool is exhausted it will use the heap. More...
#include <Cached_Allocator_With_Overflow_T.h>
Public Member Functions | |
Cached_Allocator_With_Overflow (size_t n_chunks) | |
~Cached_Allocator_With_Overflow () | |
Clear things up. More... | |
void * | malloc (size_t nbytes=sizeof(T)) |
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 | available () |
size_t | n_chunks () const |
![]() | |
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) |
Private Attributes | |
unsigned char * | begin_ |
unsigned char * | end_ |
The end of the pool. More... | |
ACE_Locked_Free_List< ACE_Cached_Mem_Pool_Node< T >, ACE_LOCK > | free_list_ |
Maintain a cached memory free list. More... | |
const size_t | n_chunks_ |
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 fixed-size allocator that caches items for quicker access but if the pool is exhausted it will use the heap.
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. If the free list is empty then memory is allocated from the heap. This way the allocations will not fail but may be slower.
Definition at line 46 of file Cached_Allocator_With_Overflow_T.h.
|
inlineexplicit |
Create a cached memory pool with n_chunks chunks each with sizeof (TYPE) size.
Definition at line 50 of file Cached_Allocator_With_Overflow_T.h.
|
inline |
Clear things up.
Definition at line 81 of file Cached_Allocator_With_Overflow_T.h.
|
inline |
How many chunks are available at this time.
Definition at line 153 of file Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::free(), and OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::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 sizeof T, and is otherwise ignored since calloc() always returns a pointer to an item of sizeof (T).
Reimplemented from ACE_New_Allocator.
Definition at line 117 of file 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 125 of file 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 133 of file Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::RtpsUdpReceiveStrategy::handle_input(), and OpenDDS::DCPS::WriteDataContainer::release_buffer().
|
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 sizeof T, and is otherwise ignored since malloc()
always returns a pointer to an item of sizeof (T).
Reimplemented from ACE_New_Allocator.
Definition at line 91 of file Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::RtpsUdpDataLink::alloc_msgblock(), OpenDDS::DCPS::TransportQueueElement::clone_mb(), OpenDDS::DCPS::WriteDataContainer::copy_and_prepend(), OpenDDS::DCPS::RtpsUdpReceiveStrategy::handle_input(), OpenDDS::DCPS::WriteDataContainer::obtain_buffer(), OpenDDS::DCPS::WriteDataContainer::obtain_buffer_for_control(), and OpenDDS::DCPS::RtpsUdpReceiveStrategy::RtpsUdpReceiveStrategy().
|
inline |
Definition at line 155 of file Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::Cached_Allocator_With_Overflow().
|
private |
Remember how we allocate the memory in the first place so we can clear things up later.
Definition at line 160 of file Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::Cached_Allocator_With_Overflow(), and OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::~Cached_Allocator_With_Overflow().
|
private |
The end of the pool.
Definition at line 162 of file Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::Cached_Allocator_With_Overflow(), and OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::free().
|
private |
Maintain a cached memory free list.
Definition at line 165 of file Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::available(), OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::Cached_Allocator_With_Overflow(), OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::free(), and OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::malloc().
|
private |
Definition at line 167 of file Cached_Allocator_With_Overflow_T.h.
Referenced by OpenDDS::DCPS::Cached_Allocator_With_Overflow< ACE_Message_Block, RECEIVE_SYNCH >::n_chunks().