mbo::reallocator< __ValueType > Class Template Reference

Allocator that supports reallocation. More...

#include <reallocator.h>

Inheritance diagram for mbo::reallocator< __ValueType >:

Inheritance graph
{mbo::mem_reallocator\< __ValueType \>\n||+ allocate()\l+ deallocate()\l+ reallocate()\l+ move()\l}{mbo::allocator\< __ValueType \>\n||+ address()\l+ address()\l+ allocate()\l+ deallocate()\l+ construct()\l+ max_size()\l}{mbo::allocator\< __ValueType, __ReferenceType \>\n||+ address()\l+ address()\l+ allocate()\l+ deallocate()\l+ construct()\l+ max_size()\l}
[legend]
Collaboration diagram for mbo::reallocator< __ValueType >:

Collaboration graph
{mbo::allocator\< __ValueType \>\n||+ address()\l+ address()\l+ allocate()\l+ deallocate()\l+ construct()\l+ max_size()\l}{mbo::allocator\< __ValueType, __ReferenceType \>\n||+ address()\l+ address()\l+ allocate()\l+ deallocate()\l+ construct()\l+ max_size()\l}
[legend]

List of all members.

Public Member Functions

pointer reallocate (pointer ptr, size_type old_size, size_type new_size) throw ( bad_alloc )
void move (pointer dst, pointer src, size_type size)


Detailed Description

template<class __ValueType>
class mbo::reallocator< __ValueType >

Allocator that supports reallocation.

This allocator uses memmove() directly when reallocating element space to copy elements from the orignal location to the new location without the need to call constructors and destructors (not even inplace destructors).

See also:
TDynamicArray

MBO_THROWS_EXCEPTIONS

Definition at line 169 of file reallocator.h.


Member Function Documentation

template<class __ValueType>
pointer mbo::reallocator< __ValueType >::reallocate ( pointer  ptr,
size_type  old_size,
size_type  new_size 
) throw ( bad_alloc ) [inline]

Reallocate element space

Parameters:
ptr original pointer
old_size original number of elements
new_size new number of elements
Returns:
reallocated element space
Exceptions:
bad_alloc if no memory could be allocated

Reimplemented in mbo::mem_reallocator< __ValueType >.

Definition at line 181 of file reallocator.h.

References mbo::allocator< __ValueType >::allocate(), mbo::allocator< __ValueType >::deallocate(), mbo_throw_if_not, min, and mbo::reallocator< __ValueType >::move().

00182     {
00183         pointer dst = allocate(new_size);
00184 
00185         mbo_throw_if_not(bad_alloc, dst || !new_size);
00186         if (dst && ptr)
00187         {
00188             move(dst, ptr, min(new_size, old_size));
00189         }
00190         if (ptr && (dst || !new_size))
00191         {
00192             deallocate(ptr, old_size);
00193         }
00194         return dst;
00195     }

Here is the call graph for this function:

mbo::allocator\< __ValueType \>::allocatembo::allocator\< __ValueType \>::deallocatembo::reallocator::move

template<class __ValueType>
void mbo::reallocator< __ValueType >::move ( pointer  dst,
pointer  src,
size_type  size 
) [inline]

Moves size elements from src to dst.

Parameters:
dst destination pointer
src source pointer
size number of elements to move
Warning:
We are doing a raw memory operation since we cannot accept unbalanced constructor / deestructor calls. Which would disbalance reference counters.

We could also use std::uninitialized_copy() but this would not work when using std::allocator as base class because then we would allocate value_type element spaces and thus call their constructors.

Reimplemented in mbo::mem_reallocator< __ValueType >.

Definition at line 212 of file reallocator.h.

Referenced by mbo::reallocator< __ValueType >::reallocate().

00213     {
00214         //std::uninitialized_copy(src, src + size, dst);
00215         memmove(dst, src, size * sizeof(value_type));
00216     }


The documentation for this class was generated from the following file:
  Hosted on code.google.com  
© Marcus Börger
Generated on Fri Jan 18 21:21:13 2008 for MBO-lib by doxygen 1.5.4