ACE 8.0.1
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
ACE_Dynamic_Cached_Allocator< ACE_LOCK > Class Template Reference

A size-based allocator that caches blocks for quicker access. More...

#include <Malloc_T.h>

Inheritance diagram for ACE_Dynamic_Cached_Allocator< ACE_LOCK >:
Inheritance graph
[legend]
Collaboration diagram for ACE_Dynamic_Cached_Allocator< ACE_LOCK >:
Collaboration graph
[legend]

Public Member Functions

 ACE_Dynamic_Cached_Allocator (size_t n_chunks, size_t chunk_size)
 
 ~ACE_Dynamic_Cached_Allocator ()
 Clear things up.
 
voidmalloc (size_t nbytes=0)
 
virtual voidcalloc (size_t nbytes, char initial_value='\0')
 
virtual voidcalloc (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.
 
size_t pool_depth ()
 Return the number of chunks available in the cache.
 
- Public Member Functions inherited from ACE_New_Allocator
virtual int remove ()
 These methods are no-ops.
 
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.
 
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 () const
 Dump the state of the object.
 
- Public Member Functions inherited from ACE_Allocator
 ACE_Allocator ()
 "No-op" constructor (needed to make certain compilers happy).
 
virtual ~ACE_Allocator ()
 Virtual destructor.
 

Private Attributes

charpool_
 
ACE_Locked_Free_List< ACE_Cached_Mem_Pool_Node< char >, ACE_LOCK > free_list_
 
size_t chunk_size_
 Remember the size of our chunks.
 

Additional Inherited Members

- Public Types inherited from ACE_Allocator
typedef size_t size_type
 Unsigned integer type used for specifying memory block lengths.
 
- Static Public Member Functions inherited from ACE_Allocator
static ACE_Allocatorinstance ()
 Get pointer to a default ACE_Allocator.
 
static ACE_Allocatorinstance (ACE_Allocator *)
 
static void close_singleton ()
 Delete the dynamically allocated Singleton.
 

Detailed Description

template<class ACE_LOCK>
class ACE_Dynamic_Cached_Allocator< ACE_LOCK >

A size-based allocator that caches blocks for quicker access.

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.

See also
ACE_Cached_Allocator

Constructor & Destructor Documentation

◆ ACE_Dynamic_Cached_Allocator()

template<class ACE_LOCK >
ACE_Dynamic_Cached_Allocator< ACE_LOCK >::ACE_Dynamic_Cached_Allocator ( size_t n_chunks,
size_t chunk_size )

Create a cached memory pool with n_chunks chunks each with chunk_size size.

◆ ~ACE_Dynamic_Cached_Allocator()

template<class ACE_LOCK >
ACE_Dynamic_Cached_Allocator< ACE_LOCK >::~ACE_Dynamic_Cached_Allocator ( )

Clear things up.

Member Function Documentation

◆ calloc() [1/2]

template<class ACE_LOCK >
void * ACE_Dynamic_Cached_Allocator< ACE_LOCK >::calloc ( size_t n_elem,
size_t elem_size,
char initial_value = '\0' )
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.

◆ calloc() [2/2]

template<class ACE_LOCK >
void * ACE_Dynamic_Cached_Allocator< ACE_LOCK >::calloc ( size_t nbytes,
char initial_value = '\0' )
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 chunk_size, and is otherwise ignored since calloc() always returns a pointer to an item of chunk_size.

Reimplemented from ACE_New_Allocator.

◆ free()

template<class ACE_LOCK >
void ACE_Dynamic_Cached_Allocator< ACE_LOCK >::free ( void * ptr)
virtual

Return a chunk of memory back to free list cache.

Reimplemented from ACE_New_Allocator.

◆ malloc()

template<class ACE_LOCK >
void * ACE_Dynamic_Cached_Allocator< ACE_LOCK >::malloc ( size_t nbytes = 0)
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 chunk_size, and is otherwise ignored since malloc() always returns a pointer to an item of chunk_size size.

Reimplemented from ACE_New_Allocator.

◆ pool_depth()

template<class ACE_LOCK >
size_t ACE_Dynamic_Cached_Allocator< ACE_LOCK >::pool_depth ( )
inline

Return the number of chunks available in the cache.

Member Data Documentation

◆ chunk_size_

template<class ACE_LOCK >
size_t ACE_Dynamic_Cached_Allocator< ACE_LOCK >::chunk_size_
private

Remember the size of our chunks.

◆ free_list_

template<class ACE_LOCK >
ACE_Locked_Free_List<ACE_Cached_Mem_Pool_Node<char>, ACE_LOCK> ACE_Dynamic_Cached_Allocator< ACE_LOCK >::free_list_
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*).

◆ pool_

template<class ACE_LOCK >
char* ACE_Dynamic_Cached_Allocator< ACE_LOCK >::pool_
private

Remember how we allocate the memory in the first place so we can clear things up later.


The documentation for this class was generated from the following files: