# ace::MemoryBlock< _Type > Class Template Reference

Memory block is designed to keep large continuous chunk of memory within and provides methods for subsequent transfer of small pieces to client subjects. More...

`#include <pool.h>`

List of all members.

## Public Member Functions
| MemoryBlock (size_t block_size)
| Constructor tries to allocate memory `block_size` units long.
virtual | ~MemoryBlock (void) throw ()
| Destructor frees allocated memory.
_Type * | assigned_mem_bound (void) const throw ()
size_t | count_free_memory (void) const throw ()
bool | is_full (void) const throw ()
_Type * | get_memory (size_t mem_size=1) throw ()
| Returns pointer to the next `mem_size` units long chunk of memory and advances internal free memory pointer.
_Type * | lower_bound (void) const throw ()
_Type * | upper_bound (void) const throw ()
size_t | unit_size (void) const throw ()
## Protected Member Functions
| MemoryBlock (const MemoryBlock< _Type > &mpb)
| No copy constructs.
MemoryBlock< _Type > & | operator= (const MemoryBlock< _Type > &mpb)
| No assignments.
## Private Attributes
const size_t | _unit_size
| Stored unit size (sizeof(_Type) result).
_Type * | _memory
| Pointers to the start of the block Following must be always true: _memory <= _free <= _upper_bound.
_Type * | _free
| Pointer to the beginning of free memory.
_Type * | _upper_bound
| Pointers to the first address behind block memory.

## Detailed Description

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

Memory block is designed to keep large continuous chunk of memory within and provides methods for subsequent transfer of small pieces to client subjects.

Parameters:

  | _Type | Type to be stored within the block.

## Constructor & Destructor Documentation

template<class _Type>

ace::MemoryBlock< _Type >::MemoryBlock | ( | const MemoryBlock< _Type > & | mpb | ) | `[protected]`

No copy constructs.

template<class _Type>

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

Constructor tries to allocate memory `block_size` units long.

If allocation succeeds both `_start` and `_free` point to the newly allocated memory, otherwise std::bad_alloc is throwed.

Parameters:

  | block_size | Size of newly allocated memory (in template type units).

Exceptions:

  | std::bad_alloc | When the memory for block cannot be allocated.

template<class _Type>

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

Destructor frees allocated memory.

## Member Function Documentation

template<class _Type>

MemoryBlock<_Type>& ace::MemoryBlock< _Type >::operator= | ( | const MemoryBlock< _Type > & | mpb | ) | `[protected]`

No assignments.

template<class _Type>

_Type* ace::MemoryBlock< _Type >::assigned_mem_bound | ( | void |  | ) | const throw ()`[inline]`

Returns:
  Pointer to the next free chunk of memory within the block.

template<class _Type>

size_t ace::MemoryBlock< _Type >::count_free_memory | ( | void |  | ) | const throw ()`[inline]`

Returns:
  Count of remaining free space within block.

template<class _Type>

bool ace::MemoryBlock< _Type >::is_full | ( | void |  | ) | const throw ()`[inline]`

Returns:
  True, if no more memory can be assigned within this block.

template<class _Type>

_Type* ace::MemoryBlock< _Type >::get_memory | ( | size_t | mem_size = `1` | ) | throw ()`[inline]`

Returns pointer to the next `mem_size` units long chunk of memory and advances internal free memory pointer.

In case there is not enough of memory in the pool NULL is returned.

Parameters:

  | mem_size | Size of demanded memory (in units stored, not in bytes!).

Returns:
  Pointer to free memory of size `mem_size` or NULL.

template<class _Type>

_Type* ace::MemoryBlock< _Type >::lower_bound | ( | void |  | ) | const throw ()`[inline]`

Returns:
  Pointer to the first address within the memory block.

template<class _Type>

_Type* ace::MemoryBlock< _Type >::upper_bound | ( | void |  | ) | const throw ()`[inline]`

Returns:
  Pointer to the first address behind the memory block.

template<class _Type>

size_t ace::MemoryBlock< _Type >::unit_size | ( | void |  | ) | const throw ()`[inline]`

Returns:
  Size of stored unit (result of sizeof(_Type) operator).

## Member Data Documentation

template<class _Type>

const size_t ace::MemoryBlock< _Type >::_unit_size`[private]`

Stored unit size (sizeof(_Type) result).

template<class _Type>

_Type* ace::MemoryBlock< _Type >::_memory`[private]`

Pointers to the start of the block Following must be always true: _memory <= _free <= _upper_bound.

template<class _Type>

_Type* ace::MemoryBlock< _Type >::_free`[private]`

Pointer to the beginning of free memory.

Following must be always true: _memory <= _free <= _upper_bound.

template<class _Type>

_Type* ace::MemoryBlock< _Type >::_upper_bound`[private]`

Pointers to the first address behind block memory.

Following must be always true: _memory <= _free <= _upper_bound.

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

- proto/Source/pool.h