Allocates a block of memory with cleanup. More...
Classes | |
struct | rebind |
Public Types | |
typedef AllocatorBase< T > ::value_type | value_type |
typedef AllocatorBase< T > ::size_type | size_type |
typedef AllocatorBase< T > ::difference_type | difference_type |
typedef AllocatorBase< T >::pointer | pointer |
typedef AllocatorBase< T > ::const_pointer | const_pointer |
typedef AllocatorBase< T > ::reference | reference |
typedef AllocatorBase< T > ::const_reference | const_reference |
Public Member Functions | |
pointer | allocate (size_type size, const void *ptr=NULL) |
Allocates a block of memory. | |
void | deallocate (void *ptr, size_type size) |
Deallocates a block of memory. | |
pointer | reallocate (T *oldPtr, size_type oldSize, size_type newSize, bool preserve) |
Reallocates a block of memory. | |
pointer | address (reference r) const |
const_pointer | address (const_reference r) const |
void | construct (pointer p, const T &val) |
template<typename U , typename... Args> | |
void | construct (U *ptr, Args &&...args) |
Constructs a new U using variadic arguments. | |
void | destroy (pointer p) |
template<typename U > | |
void | destroy (U *ptr) |
Destroys an U constructed with variadic arguments. | |
size_type | max_size () const |
Returns the maximum number of elements the allocator can provide. |
Allocates a block of memory with cleanup.
T | class or type | |
T_Align16 | boolean that determines whether allocations should be aligned on 16-byte boundaries |
If T_Align16 is true, then AllocatorWithCleanup calls AlignedAllocate() for memory allocations. If T_Align16 is false, then AllocatorWithCleanup() calls UnalignedAllocate() for memory allocations.
Template parameter T_Align16 is effectively controlled by cryptlib.h and mirrors CRYPTOPP_BOOL_ALIGN16. CRYPTOPP_BOOL_ALIGN16 is often used as the template parameter.
Definition at line 151 of file secblock.h.
pointer AllocatorWithCleanup< T, T_Align16 >::allocate | ( | size_type | size, | |
const void * | ptr = NULL | |||
) | [inline] |
Allocates a block of memory.
ptr | the size of the allocation | |
size | the size of the allocation |
InvalidArgument |
allocate() first checks the size of the request. If it is non-0 and less than max_size(), then an attempt is made to fulfill the request using either AlignedAllocate() or UnalignedAllocate().
AlignedAllocate() is used if T_Align16 is true. UnalignedAllocate() used if T_Align16 is false.
This is the C++ *Placement New* operator. ptr is not used, and the function asserts in Debug builds if ptr is non-NULL.
Definition at line 171 of file secblock.h.
void AllocatorWithCleanup< T, T_Align16 >::deallocate | ( | void * | ptr, | |
size_type | size | |||
) | [inline] |
Deallocates a block of memory.
ptr | the size of the allocation | |
size | the size of the allocation |
Internally, SecureWipeArray() is called before deallocating the memory. Once the memory block is wiped or zeroized, AlignedDeallocate() or UnalignedDeallocate() is called.
AlignedDeallocate() is used if T_Align16 is true. UnalignedDeallocate() used if T_Align16 is false.
Definition at line 195 of file secblock.h.
pointer AllocatorWithCleanup< T, T_Align16 >::reallocate | ( | T * | oldPtr, | |
size_type | oldSize, | |||
size_type | newSize, | |||
bool | preserve | |||
) | [inline] |
Reallocates a block of memory.
oldPtr | the previous allocation | |
oldSize | the size of the previous allocation | |
newSize | the new, requested size | |
preserve | flag that indicates if the old allocation should be preserved |
Internally, reallocate() calls StandardReallocate().
If preserve is true, then index 0 is used to begin copying the old memory block to the new one. If the block grows, then the old array is copied in its entirety. If the block shrinks, then only newSize elements are copied from the old block to the new one.
Definition at line 221 of file secblock.h.
void AllocatorBase< T >::construct | ( | U * | ptr, | |
Args &&... | args | |||
) | [inline, inherited] |
Constructs a new U using variadic arguments.
U | the type to be forwarded | |
Args | the arguments to be forwarded |
ptr | pointer to type U | |
args | variadic arguments |
This is a C++11 feature. It is available when CRYPTOPP_CXX11_VARIADIC_TEMPLATES is defined. The define is controlled by compiler versions detected in config.h.
Definition at line 67 of file secblock.h.
void AllocatorBase< T >::destroy | ( | U * | ptr | ) | [inline, inherited] |
Destroys an U constructed with variadic arguments.
U | the type to be forwarded |
This is a C++11 feature. It is available when CRYPTOPP_CXX11_VARIADIC_TEMPLATES is defined. The define is controlled by compiler versions detected in config.h.
Definition at line 74 of file secblock.h.
size_type AllocatorBase< T >::max_size | ( | ) | const [inline, inherited] |
Returns the maximum number of elements the allocator can provide.
Internally, preprocessor macros are used rather than std::numeric_limits because the latter is not a constexpr. Some compilers, like Clang, do not optimize it well under all circumstances. Compilers like GCC, ICC and MSVC appear to optimize it well in either form.
Reimplemented in NullAllocator< T >, FixedSizeAllocatorWithCleanup< T, S, A, T_Align16 >, NullAllocator< unsigned int >, NullAllocator< word16 >, NullAllocator< byte >, NullAllocator< T_HashWordType >, NullAllocator< Word >, NullAllocator< word64 >, NullAllocator< word32 >, FixedSizeAllocatorWithCleanup< word32, S >, FixedSizeAllocatorWithCleanup< Word, S >, FixedSizeAllocatorWithCleanup< T, S, NullAllocator< T >, T_Align16 >, FixedSizeAllocatorWithCleanup< word64, S >, FixedSizeAllocatorWithCleanup< T_HashWordType, S >, FixedSizeAllocatorWithCleanup< word64, S, NullAllocator< word64 >, T_Align16 >, FixedSizeAllocatorWithCleanup< word32, S, NullAllocator< word32 >, true >, FixedSizeAllocatorWithCleanup< word16, S >, FixedSizeAllocatorWithCleanup< byte, S >, FixedSizeAllocatorWithCleanup< word32, S, NullAllocator< word32 >, T_Align16 >, FixedSizeAllocatorWithCleanup< T_HashWordType, S, NullAllocator< T_HashWordType >, T_Align16 >, and FixedSizeAllocatorWithCleanup< unsigned int, S >.
Definition at line 55 of file secblock.h.