Botan  2.7.0
Crypto and TLS for C++11
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) BOTAN_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 19 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 
)

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 74 of file locking_allocator.cpp.

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

75  {
76  static mlock_allocator mlock;
77  return mlock;
78  }
mlock_allocator(const mlock_allocator &)=delete

◆ operator=()

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

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