Crypto++ 8.7
Free C++ class library of cryptographic schemes
Classes | Public Types | Public Member Functions | List of all members
AllocatorWithCleanup< T, T_Align16 > Class Template Reference

Allocates a block of memory with cleanup. More...

#include <secblock.h>

+ Inheritance diagram for AllocatorWithCleanup< T, T_Align16 >:

Classes

struct  rebind
 Template class member Rebind. More...
 

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 Types inherited from AllocatorBase< T >
typedef T value_type
 
typedef size_t size_type
 
typedef std::ptrdiff_t difference_type
 
typedef T * pointer
 
typedef const T * const_pointer
 
typedef T & reference
 
typedef const T & const_reference
 

Public Member Functions

pointer allocate (size_type size, const void *ptr=NULL)
 Allocates a block of memory. More...
 
void deallocate (void *ptr, size_type size)
 Deallocates a block of memory. More...
 
pointer reallocate (T *oldPtr, size_type oldSize, size_type newSize, bool preserve)
 Reallocates a block of memory. More...
 
- Public Member Functions inherited from AllocatorBase< T >
pointer address (reference r) const
 
const_pointer address (const_reference r) const
 
void construct (pointer p, const T &val)
 
void destroy (pointer p)
 
size_type max_size () const
 Returns the maximum number of elements the allocator can provide. More...
 
template<typename V , typename... Args>
void construct (V *ptr, Args &&... args)
 Constructs a new V using variadic arguments. More...
 
template<typename V >
void destroy (V *ptr)
 Destroys an V constructed with variadic arguments. More...
 

Additional Inherited Members

- Static Public Attributes inherited from AllocatorBase< T >
static const size_type ELEMS_MAX = ...
 Returns the maximum number of elements the allocator can provide. More...
 

Detailed Description

template<class T, bool T_Align16 = false>
class AllocatorWithCleanup< T, T_Align16 >

Allocates a block of memory with cleanup.

Template Parameters
Tclass or type
T_Align16boolean that determines whether allocations should be aligned on a 16-byte boundary

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 187 of file secblock.h.

Member Typedef Documentation

◆ value_type

template<class T , bool T_Align16 = false>
typedef AllocatorBase<T>::value_type AllocatorWithCleanup< T, T_Align16 >::value_type

Definition at line 190 of file secblock.h.

◆ size_type

template<class T , bool T_Align16 = false>
typedef AllocatorBase<T>::size_type AllocatorWithCleanup< T, T_Align16 >::size_type

Definition at line 190 of file secblock.h.

◆ difference_type

template<class T , bool T_Align16 = false>
typedef AllocatorBase<T>::difference_type AllocatorWithCleanup< T, T_Align16 >::difference_type

Definition at line 190 of file secblock.h.

◆ pointer

template<class T , bool T_Align16 = false>
typedef AllocatorBase<T>::pointer AllocatorWithCleanup< T, T_Align16 >::pointer

Definition at line 190 of file secblock.h.

◆ const_pointer

template<class T , bool T_Align16 = false>
typedef AllocatorBase<T>::const_pointer AllocatorWithCleanup< T, T_Align16 >::const_pointer

Definition at line 190 of file secblock.h.

◆ reference

template<class T , bool T_Align16 = false>
typedef AllocatorBase<T>::reference AllocatorWithCleanup< T, T_Align16 >::reference

Definition at line 190 of file secblock.h.

◆ const_reference

template<class T , bool T_Align16 = false>
typedef AllocatorBase<T>::const_reference AllocatorWithCleanup< T, T_Align16 >::const_reference

Definition at line 190 of file secblock.h.

Member Function Documentation

◆ allocate()

template<class T , bool T_Align16 = false>
pointer AllocatorWithCleanup< T, T_Align16 >::allocate ( size_type  size,
const void *  ptr = NULL 
)
inline

Allocates a block of memory.

Parameters
ptrthe size of the allocation
sizethe size of the allocation, in elements
Returns
a memory block
Exceptions
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.

See also
CallNewHandler() for the methods used to recover from a failed allocation attempt.
Note
size is the count of elements, and not the number of bytes

Definition at line 206 of file secblock.h.

◆ deallocate()

template<class T , bool T_Align16 = false>
void AllocatorWithCleanup< T, T_Align16 >::deallocate ( void *  ptr,
size_type  size 
)
inline

Deallocates a block of memory.

Parameters
ptrthe pointer for the allocation
sizethe size of the allocation, in elements

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 229 of file secblock.h.

◆ reallocate()

template<class T , bool T_Align16 = false>
pointer AllocatorWithCleanup< T, T_Align16 >::reallocate ( T *  oldPtr,
size_type  oldSize,
size_type  newSize,
bool  preserve 
)
inline

Reallocates a block of memory.

Parameters
oldPtrthe previous allocation
oldSizethe size of the previous allocation
newSizethe new, requested size
preserveflag that indicates if the old allocation should be preserved
Returns
pointer to the new memory block

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.

Note
oldSize and newSize are the count of elements, and not the number of bytes.

Definition at line 259 of file secblock.h.


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