Botan 2.19.1
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::mlock_allocator Class Referencefinal

#include <locking_allocator.h>

Public Member Functions

void * allocate (size_t num_elems, size_t elem_size)
 
bool deallocate (void *p, size_t num_elems, size_t elem_size) noexcept
 
 mlock_allocator (const mlock_allocator &)=delete
 
mlock_allocatoroperator= (const mlock_allocator &)=delete
 

Static Public Member Functions

static mlock_allocatorinstance ()
 

Detailed Description

Definition at line 21 of file locking_allocator.h.

Constructor & Destructor Documentation

◆ mlock_allocator()

Botan::mlock_allocator::mlock_allocator ( const mlock_allocator )
delete

Member Function Documentation

◆ allocate()

void * Botan::mlock_allocator::allocate ( size_t  num_elems,
size_t  elem_size 
)

Definition at line 14 of file locking_allocator.cpp.

15 {
16 if(!m_pool)
17 return nullptr;
18
19 const size_t n = num_elems * elem_size;
20 if(n / elem_size != num_elems)
21 return nullptr; // overflow!
22
23 return m_pool->allocate(n);
24 }

◆ deallocate()

bool Botan::mlock_allocator::deallocate ( void *  p,
size_t  num_elems,
size_t  elem_size 
)
noexcept

Definition at line 26 of file locking_allocator.cpp.

27 {
28 if(!m_pool)
29 return false;
30
31 size_t n = num_elems * elem_size;
32
33 /*
34 We return nullptr in allocate if there was an overflow, so if an
35 overflow occurs here we know the pointer was not allocated by this pool.
36 */
37 if(n / elem_size != num_elems)
38 return false;
39
40 return m_pool->deallocate(p, n);
41 }

◆ instance()

mlock_allocator & Botan::mlock_allocator::instance ( )
static

Definition at line 69 of file locking_allocator.cpp.

70 {
71 static mlock_allocator mlock;
72 return mlock;
73 }
mlock_allocator(const mlock_allocator &)=delete

Referenced by Botan::allocate_memory(), Botan::deallocate_memory(), and Botan::initialize_allocator().

◆ operator=()

mlock_allocator & Botan::mlock_allocator::operator= ( const mlock_allocator )
delete

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