#include <reallocator.h>
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) |
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).
Definition at line 169 of file reallocator.h.
pointer mbo::reallocator< __ValueType >::reallocate | ( | pointer | ptr, | |
size_type | old_size, | |||
size_type | new_size | |||
) | throw ( bad_alloc ) [inline] |
Reallocate element space
ptr | original pointer | |
old_size | original number of elements | |
new_size | new number of elements |
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 }
void mbo::reallocator< __ValueType >::move | ( | pointer | dst, | |
pointer | src, | |||
size_type | size | |||
) | [inline] |
Moves size elements from src to dst.
dst | destination pointer | |
src | source pointer | |
size | number of elements to move |
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 }
Hosted on code.google.com | © Marcus Börger | Generated on Fri Jan 18 21:21:13 2008 for MBO-lib by ![]() |