# ace::RandomSizedMemoryPool< _Type > Class Template Reference

RandomSizedMemoryPool, as its name suggests, allows to transfer various-sized chunks of memory. More...

`#include <pool.h>`

Inherits ace::MemoryPool< _Type, ace::MemoryBlock< _Type > >.

List of all members.

## Public Member Functions
| RandomSizedMemoryPool (size_t block_size) throw ()
| Constructor initializes new pool, but does not allocate any memory.
virtual | ~RandomSizedMemoryPool (void) throw ()
| Destructor frees all allocated memory by calling clear().
virtual void | clear (void) throw ()
| Frees all the allocated memory (deletes all memory pool blocks).
virtual _Type * | get_memory (size_t mem_size)
| Returns pointer to free memory of size `mem_size`.
## Protected Types
typedef MemoryBlock< _Type > | _block_type
typedef std::multimap< size_t, _block_type * > | _blocks_free_sizes_map
| Type used to keep info about remaining (available) memory in all existing pool blocks, except the one recently used (see below).
## Protected Member Functions
virtual _block_type * | create_new_block (void)
| Creates new memory block.
## Protected Attributes
_block_type * | _recently_used_block
| Pool block recently used for allocation.
_blocks_free_sizes_map | _mem_blocks
| Mapping from size of available free memory in certain block to the pointer to its instance.

## Detailed Description

### template<class _Type>
class ace::RandomSizedMemoryPool< _Type >

RandomSizedMemoryPool, as its name suggests, allows to transfer various-sized chunks of memory.

It's perfectly useful to stored random-sized strings (as char sequences). Note that class is derived from MemoryPool template class with given type and MemoryBlock as particular type of block to be used.

Parameters:

  | _Type | Stored unit type.

## Member Typedef Documentation

template<class _Type>

typedef MemoryBlock<_Type> ace::RandomSizedMemoryPool< _Type >::_block_type`[protected]`

template<class _Type>

typedef std::multimap<size_t, _block_type *> ace::RandomSizedMemoryPool< _Type >::_blocks_free_sizes_map`[protected]`

Type used to keep info about remaining (available) memory in all existing pool blocks, except the one recently used (see below).

## Constructor & Destructor Documentation

template<class _Type>

ace::RandomSizedMemoryPool< _Type >::RandomSizedMemoryPool | ( | size_t | block_size | ) | throw ()`[inline]`

Constructor initializes new pool, but does not allocate any memory.

Parameters:

  | block_size | Size of memory blocks within the pool.

template<class _Type>

virtual ace::RandomSizedMemoryPool< _Type >::~RandomSizedMemoryPool | ( | void |  | ) | throw ()`[inline, virtual]`

Destructor frees all allocated memory by calling clear().

## Member Function Documentation

template<class _Type>

virtual _block_type* ace::RandomSizedMemoryPool< _Type >::create_new_block | ( | void |  | ) | `[inline, protected, virtual]`

Creates new memory block.

Returns:
  Pointer to newly created memory pool block.

Exceptions:

  | std::bad_alloc | when there is not enough memory left to allocate new pool block.

Implements ace::MemoryPool< _Type, _Block >.

template<class _Type>

virtual void ace::RandomSizedMemoryPool< _Type >::clear | ( | void |  | ) | throw ()`[inline, virtual]`

Frees all the allocated memory (deletes all memory pool blocks).

Use only when there is a guaranty that there are no pointers pointing at the memory pool left.

Implements ace::MemoryPool< _Type, _Block >.

template<class _Type>

virtual _Type* ace::RandomSizedMemoryPool< _Type >::get_memory | ( | size_t | mem_size | ) | `[inline, virtual]`

Returns pointer to free memory of size `mem_size`.

If `mem_size` is bigger than size of memory blocks within the pool, NULL is returned. Moreover if there is not enough memory and new memory cannot be allocated, function throws std::bad_alloc. there is not enough free memory.

Parameters:

  | mem_size | The size of demanded memory.

Returns:
  Pointer to beginning of the returned memory or NULL if `mem_size` is invalid.

Exceptions:

  | std::bad_alloc | When there is no more memory available.

Implements ace::MemoryPool< _Type, _Block >.

## Member Data Documentation

template<class _Type>

_block_type* ace::RandomSizedMemoryPool< _Type >::_recently_used_block`[protected]`

Pool block recently used for allocation.

template<class _Type>

_blocks_free_sizes_map ace::RandomSizedMemoryPool< _Type >::_mem_blocks`[protected]`

Mapping from size of available free memory in certain block to the pointer to its instance.

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

- proto/Source/pool.h