Crypto++ 8.7
Free C++ class library of cryptographic schemes
|
Functions for allocating aligned buffers. More...
Go to the source code of this file.
Functions | |
CRYPTOPP_DLL void | CallNewHandler () |
Attempts to reclaim unused memory. More... | |
CRYPTOPP_DLL void * | AlignedAllocate (size_t size) |
Allocates a buffer on 16-byte boundary. More... | |
CRYPTOPP_DLL void | AlignedDeallocate (void *ptr) |
Frees a buffer allocated with AlignedAllocate. More... | |
CRYPTOPP_DLL void * | UnalignedAllocate (size_t size) |
Allocates a buffer. More... | |
CRYPTOPP_DLL void | UnalignedDeallocate (void *ptr) |
Frees a buffer allocated with UnalignedAllocate. More... | |
Functions for allocating aligned buffers.
Definition in file allocate.h.
CRYPTOPP_DLL void CallNewHandler | ( | ) |
Attempts to reclaim unused memory.
bad_alloc |
In the normal course of running a program, a request for memory normally succeeds. If a call to AlignedAllocate or UnalignedAllocate fails, then CallNewHandler is called in n effort to recover. Internally, CallNewHandler calls set_new_handler(nullptr) in an effort to free memory. There is no guarantee CallNewHandler will be able to obtain more memory so an allocation succeeds. If the call to set_new_handler fails, then CallNewHandler throws a bad_alloc exception.
bad_alloc | on failure |
CRYPTOPP_DLL void * AlignedAllocate | ( | size_t | size | ) |
Allocates a buffer on 16-byte boundary.
size | the size of the buffer |
AlignedAllocate is primarily used when the data will be processed by SSE, NEON, ARMv8 or PowerPC instructions. The assembly language routines rely on the alignment. If the alignment is not respected, then a SIGBUS could be generated on Unix and Linux, and an EXCEPTION_DATATYPE_MISALIGNMENT could be generated on Windows.
Formerly, AlignedAllocate and AlignedDeallocate were only available on certain platforms when CRYTPOPP_DISABLE_ASM was not in effect. However, Android and iOS debug simulator builds got into a state where the aligned allocator was not available and caused link failures.
CRYPTOPP_DLL void AlignedDeallocate | ( | void * | ptr | ) |
Frees a buffer allocated with AlignedAllocate.
ptr | the buffer to free |
CRYPTOPP_DLL void * UnalignedAllocate | ( | size_t | size | ) |
Allocates a buffer.
size | the size of the buffer |
CRYPTOPP_DLL void UnalignedDeallocate | ( | void * | ptr | ) |
Frees a buffer allocated with UnalignedAllocate.
ptr | the buffer to free |