Static secure memory block with cleanup. 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 Member Functions | |
FixedSizeAllocatorWithCleanup () | |
Constructs a FixedSizeAllocatorWithCleanup. | |
pointer | allocate (size_type size) |
Allocates a block of memory. | |
pointer | allocate (size_type size, const void *hint) |
Allocates a block of memory. | |
void | deallocate (void *ptr, size_type size) |
Deallocates a block of memory. | |
pointer | reallocate (pointer oldPtr, size_type oldSize, size_type newSize, bool preserve) |
Reallocates a block of memory. | |
size_type | max_size () const |
Returns the maximum number of elements the allocator can provide. | |
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. |
Static secure memory block with cleanup.
T | class or type | |
S | fixed-size of the stack-based memory block | |
A | AllocatorBase derived class for allocation and cleanup |
FixedSizeAllocatorWithCleanup provides a fixed-size, stack- based allocation at compile time. The class can grow its memory block at runtime if a suitable allocator is available. If size grows beyond S and a suitable allocator is available, then the statically allocated array is obsoleted.
Definition at line 289 of file secblock.h.
pointer FixedSizeAllocatorWithCleanup< T, S, A, T_Align16 >::allocate | ( | size_type | size | ) | [inline] |
Allocates a block of memory.
size | size of the memory block |
FixedSizeAllocatorWithCleanup provides a fixed-size, stack- based allocation at compile time. If size is less than or equal to S, then a pointer to the static array is returned.
The class can grow its memory block at runtime if a suitable allocator is available. If size grows beyond S and a suitable allocator is available, then the statically allocated array is obsoleted. If a suitable allocator is not available, as with a NullAllocator, then the function returns NULL and a runtime error eventually occurs.
Definition at line 310 of file secblock.h.
Referenced by FixedSizeAllocatorWithCleanup< unsigned int, S >::reallocate().
pointer FixedSizeAllocatorWithCleanup< T, S, A, T_Align16 >::allocate | ( | size_type | size, | |
const void * | hint | |||
) | [inline] |
Allocates a block of memory.
size | size of the memory block | |
hint | an unused hint |
FixedSizeAllocatorWithCleanup provides a fixed-size, stack- based allocation at compile time. If size is less than or equal to S, then a pointer to the static array is returned.
The class can grow its memory block at runtime if a suitable allocator is available. If size grows beyond S and a suitable allocator is available, then the statically allocated array is obsoleted. If a suitable allocator is not available, as with a NullAllocator, then the function returns NULL and a runtime error eventually occurs.
Definition at line 337 of file secblock.h.
void FixedSizeAllocatorWithCleanup< T, S, A, T_Align16 >::deallocate | ( | void * | ptr, | |
size_type | size | |||
) | [inline] |
Deallocates a block of memory.
ptr | a pointer to the memory block to deallocate | |
size | size of the memory block |
The memory block is wiped or zeroized before deallocation. If the statically allocated memory block is active, then no additional actions are taken after the wipe.
If a dynamic memory block is active, then the pointer and size are passed to the allocator for deallocation.
Definition at line 356 of file secblock.h.
Referenced by FixedSizeAllocatorWithCleanup< unsigned int, S >::reallocate().
pointer FixedSizeAllocatorWithCleanup< T, S, A, T_Align16 >::reallocate | ( | pointer | 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 |
FixedSizeAllocatorWithCleanup provides a fixed-size, stack- based allocation at compile time. If size is less than or equal to S, then a pointer to the static array is returned.
The class can grow its memory block at runtime if a suitable allocator is available. If size grows beyond S and a suitable allocator is available, then the statically allocated array is obsoleted. If a suitable allocator is not available, as with a NullAllocator, then the function returns NULL and a runtime error eventually occurs.
Definition at line 386 of file secblock.h.
size_type FixedSizeAllocatorWithCleanup< T, S, A, T_Align16 >::max_size | ( | ) | const [inline] |
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 from AllocatorBase< T >.
Definition at line 406 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.