Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# ACE_Malloc_T Class Template Reference

Define a C++ class that uses parameterized types to provide an extensible mechanism for encapsulating various of dynamic memory management strategies. More...

`#include <Malloc_T.h>`

Inheritance diagram for ACE_Malloc_T

[legend]
List of all members.

## Public Types
typedef ACE_MEM_POOL | MEMORY_POOL
typedef ACE_MEM_POOL_OPTIONS | MEMORY_POOL_OPTIONS
typedef ACE_TYPENAME ACE_CB::ACE_Name_Node | NAME_NODE
typedef ACE_TYPENAME ACE_CB::ACE_Malloc_Header | MALLOC_HEADER
## Public Methods
| ACE_Malloc_T (const ACE_TCHAR *pool_name = 0)
| ACE_Malloc_T (const ACE_TCHAR *pool_name, const ACE_TCHAR *lock_name, const ACE_MEM_POOL_OPTIONS *options = 0)
| ACE_Malloc_T (const ACE_TCHAR *pool_name, const ACE_TCHAR *lock_name, const void *options = 0)
| This is necessary to work around template bugs with certain C++ compilers.
| ~ACE_Malloc_T (void)
| Destructor.
int | ref_counter (void)
| Get Reference counter.
int | release (void)
| Release ref counter.
int | remove (void)
| Releases resources allocated by .
void* | malloc (size_t nbytes)
| Allocate <nbytes>, but don't give them any initial value.
void* | calloc (size_t nbytes, char initial_value = '\0')
| Allocate <nbytes>, giving them <initial_value>.
void* | calloc (size_t n_elem, size_t elem_size, char initial_value = '\0')
| Allocate <n_elem> each of size <elem_size>, giving them <initial_value>.
void | free (void *ptr)
| Deallocate memory pointed to by <ptr>, which must have been allocated previously by <this->malloc>.
MEMORY_POOL& | memory_pool (void)
| Returns a reference to the underlying memory pool.
int | bind (const char *name, void *pointer, int duplicates = 0)
int | trybind (const char *name, void *&pointer)
int | find (const char *name, void *&pointer)
| Locate <name> and pass out parameter via <pointer>. If found, return 0, returns -1 if failure occurs.
int | find (const char *name)
| Returns 0 if <name> is in the mapping. -1, otherwise.
int | unbind (const char *name)
int | unbind (const char *name, void *&pointer)
int | sync (ssize_t len = -1, int flags = MS_SYNC)
int | sync (void *addr, size_t len, int flags = MS_SYNC)
| Sync <len> bytes of the memory region to the backing store starting at .
int | protect (ssize_t len = -1, int prot = PROT_RDWR)
int | protect (void *addr, size_t len, int prot = PROT_RDWR)
| Change the protection of the pages of the mapped region to <prot> starting at up to <len> bytes.
ssize_t | avail_chunks (size_t size) const
ACE_LOCK& | mutex (void)
| Returns a pointer to the lock used to provide mutual exclusion to an allocator.
void | dump (void) const
| Dump the state of an object.
void* | base_addr (void)
| Return cb_ptr value.
## Public Attributes
| ACE_ALLOC_HOOK_DECLARE
| Declare the dynamic allocation hooks.
## Private Methods
int | open (void)
| Initialize the Malloc pool.
int | shared_bind (const char *name, void *pointer)
| Associate <name> with <pointer>. Assumes that locks are held by callers.
void* | shared_find (const char *name)
void* | shared_malloc (size_t nbytes)
| Allocate memory. Assumes that locks are held by callers.
void | shared_free (void *ptr)
| Deallocate memory. Assumes that locks are held by callers.
## Private Attributes
ACE_CB* | cb_ptr_
| Pointer to the control block that is stored in memory controlled by <MEMORY_POOL>.
MEMORY_POOL | memory_pool_
| Pool of memory used by to manage its freestore.
ACE_LOCK | lock_
| Lock that ensures mutual exclusion for the <MEMORY_POOL>.
## Friends
class | ACE_Malloc_LIFO_Iterator_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >
class | ACE_Malloc_FIFO_Iterator_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >

## Detailed Description

### template<ACE_MEM_POOL_1, class ACE_LOCK, class ACE_CB> template class ACE_Malloc_T

Define a C++ class that uses parameterized types to provide an extensible mechanism for encapsulating various of dynamic memory management strategies.

This class can be configured flexibly with different MEMORY_POOL strategies and different types of ACE_LOCK strategies.

## Member Typedef Documentation

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
typedef ACE_TYPENAME ACE_CB::ACE_Malloc_Header ACE_Malloc_T<, ACE_LOCK, ACE_CB>::MALLOC_HEADER

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
typedef ACE_MEM_POOL ACE_Malloc_T<, ACE_LOCK, ACE_CB>::MEMORY_POOL

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
typedef ACE_MEM_POOL_OPTIONS ACE_Malloc_T<, ACE_LOCK, ACE_CB>::MEMORY_POOL_OPTIONS

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
typedef ACE_TYPENAME ACE_CB::ACE_Name_Node ACE_Malloc_T<, ACE_LOCK, ACE_CB>::NAME_NODE

## Constructor & Destructor Documentation

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_Malloc_T<, ACE_LOCK, ACE_CB>::ACE_Malloc_T<, ACE_LOCK, ACE_CB> ( | const ACE_TCHAR * pool_name = 0 )

| Initialize ACE_Malloc. This constructor passes <pool_name> to initialize the memory pool, and uses to automatically extract out the name used for the underlying lock name (if necessary).

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_Malloc_T<, ACE_LOCK, ACE_CB>::ACE_Malloc_T<, ACE_LOCK, ACE_CB> ( | const ACE_TCHAR * pool_name,
| const ACE_TCHAR * lock_name,
| const ACE_MEM_POOL_OPTIONS * options = 0 )

| Initialize ACE_Malloc. This constructor passes <pool_name> to initialize the memory pool, and uses <lock_name> to automatically extract out the name used for the underlying lock name (if necessary). In addition, <options> is passed through to initialize the underlying memory pool.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_Malloc_T<, ACE_LOCK, ACE_CB>::ACE_Malloc_T<, ACE_LOCK, ACE_CB> ( | const ACE_TCHAR * pool_name,
| const ACE_TCHAR * lock_name,
| const void * options = 0 )

| This is necessary to work around template bugs with certain C++ compilers.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_Malloc_T<, ACE_LOCK, ACE_CB>::~ACE_Malloc_T<, ACE_LOCK, ACE_CB> ( | void )

| Destructor.

## Member Function Documentation

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ssize_t ACE_Malloc_T<, ACE_LOCK, ACE_CB>::avail_chunks ( | size_t size ) const

  | Returns a count of the number of available chunks that can hold <size> byte allocations. Function can be used to determine if you have reached a water mark. This implies a fixed amount of allocated memory. Parameters:
  size | - the chunk size of that you would like a count of
Returns: function returns the number of chunks of the given size that would fit in the currently allocated memory.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE void * ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::base_addr ( | void )

| Return cb_ptr value.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::bind ( | const char * name,
| void * pointer,
| int duplicates = 0 )

| 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.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
void * ACE_Malloc_T<, ACE_LOCK, ACE_CB>::calloc ( | size_t n_elem,
| size_t elem_size,
| char initial_value = '\0' )

| Allocate <n_elem> each of size <elem_size>, giving them <initial_value>.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
void * ACE_Malloc_T<, ACE_LOCK, ACE_CB>::calloc ( | size_t nbytes,
| char initial_value = '\0' )

| Allocate <nbytes>, giving them <initial_value>.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
void ACE_Malloc_T<, ACE_LOCK, ACE_CB>::dump ( | void ) const

| Dump the state of an object.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::find ( | const char * name )

| Returns 0 if <name> is in the mapping. -1, otherwise.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::find ( | const char * name,
| void *& pointer )

| Locate <name> and pass out parameter via <pointer>. If found, return 0, returns -1 if failure occurs.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
void ACE_Malloc_T<, ACE_LOCK, ACE_CB>::free ( | void * ptr )

| Deallocate memory pointed to by <ptr>, which must have been allocated previously by <this->malloc>.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
void * ACE_Malloc_T<, ACE_LOCK, ACE_CB>::malloc ( | size_t nbytes )

| Allocate <nbytes>, but don't give them any initial value.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE ACE_MEM_POOL & ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::memory_pool ( | void )

| Returns a reference to the underlying memory pool.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE ACE_LOCK & ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::mutex ( | void )

| Returns a pointer to the lock used to provide mutual exclusion to an allocator.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::open ( | void )`[private]`

| Initialize the Malloc pool.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE int ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::protect ( | void * addr,
| size_t len,
| int flags = PROT_RDWR )

| Change the protection of the pages of the mapped region to <prot> starting at up to <len> bytes.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE int ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::protect ( | ssize_t len = -1,
| int flags = PROT_RDWR )

| 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.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE int ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::ref_counter ( | void )

| Get Reference counter.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE int ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::release ( | void )

| Release ref counter.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::remove ( | void )

| Releases resources allocated by .

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::shared_bind ( | const char * name,
| void * pointer )`[private]`

| Associate <name> with <pointer>. Assumes that locks are held by callers.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
void * ACE_Malloc_T<, ACE_LOCK, ACE_CB>::shared_find ( | const char * name )`[private]`

| Try to locate <name>. If found, return the associated , else returns 0 if can't find the <name>. Assumes that locks are held by callers. Remember to cast the return value to ACE_CB::ACE_Name_Node*.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
void ACE_Malloc_T<, ACE_LOCK, ACE_CB>::shared_free ( | void * ptr )`[private]`

| Deallocate memory. Assumes that locks are held by callers.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
void * ACE_Malloc_T<, ACE_LOCK, ACE_CB>::shared_malloc ( | size_t nbytes )`[private]`

| Allocate memory. Assumes that locks are held by callers.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE int ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::sync ( | void * addr,
| size_t len,
| int flags = MS_SYNC )

| Sync <len> bytes of the memory region to the backing store starting at .

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_INLINE int ACE_Malloc_T< ACE_MEM_POOL_2,ACE_LOCK,ACE_CB >::sync ( | ssize_t len = -1,
| int flags = MS_SYNC )

| Sync <len> bytes of the memory region to the backing store starting at <this->base_addr_>. If <len> == -1 then sync the whole region.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::trybind ( | const char * name,
| void *& pointer )

| 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.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::unbind ( | const char * name,
| void *& pointer )

| Unbind (remove) one association of <name> to <pointer>. Returns the value of pointer in case the caller needs to deallocate memory. If you want to remove all occurrences of <name> you'll need to call this method multiple times until it fails...

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
int ACE_Malloc_T<, ACE_LOCK, ACE_CB>::unbind ( | const char * name )

| Unbind (remove) the name from the map. Don't return the pointer to the caller. If you want to remove all occurrences of <name> you'll need to call this method multiple times until it fails...

## Friends And Related Function Documentation

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
class ACE_Malloc_FIFO_Iterator_T`[friend]`

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
class ACE_Malloc_LIFO_Iterator_T`[friend]`

## Member Data Documentation

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_Malloc_T<, ACE_LOCK, ACE_CB>::ACE_ALLOC_HOOK_DECLARE

| Declare the dynamic allocation hooks.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_CB * ACE_Malloc_T<, ACE_LOCK, ACE_CB>::cb_ptr_`[private]`

| Pointer to the control block that is stored in memory controlled by <MEMORY_POOL>.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
ACE_LOCK ACE_Malloc_T<, ACE_LOCK, ACE_CB>::lock_`[private]`

| Lock that ensures mutual exclusion for the <MEMORY_POOL>.

template<ACE_MEM_POOL_1, classACE_LOCK, classACE_CB>
MEMORY_POOL ACE_Malloc_T<, ACE_LOCK, ACE_CB>::memory_pool_`[private]`

| Pool of memory used by to manage its freestore.

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

- Malloc_T.h
- Malloc_T.cpp
- Malloc_T.i