Botan 1.10.17
Botan::Allocator Class Referenceabstract

#include <allocate.h>

Inheritance diagram for Botan::Allocator:
Botan::Malloc_Allocator Botan::Pooling_Allocator Botan::Locking_Allocator Botan::MemoryMapping_Allocator

Public Member Functions

virtual void * allocate (size_t n)=0
virtual void deallocate (void *ptr, size_t n)=0
virtual void destroy ()
virtual void init ()
virtual std::string type () const =0
virtual ~Allocator ()

Static Public Member Functions

static Allocatorget (bool locking)

Detailed Description

Allocator Interface

Definition at line 19 of file allocate.h.

Constructor & Destructor Documentation

◆ ~Allocator()

virtual Botan::Allocator::~Allocator ( )
inlinevirtual

Definition at line 60 of file allocate.h.

60{}

Member Function Documentation

◆ allocate()

virtual void * Botan::Allocator::allocate ( size_t n)
pure virtual

Allocate a block of memory

Parameters
nhow many bytes to allocate
Returns
pointer to n bytes of memory

Implemented in Botan::Malloc_Allocator, and Botan::Pooling_Allocator.

◆ deallocate()

virtual void Botan::Allocator::deallocate ( void * ptr,
size_t n )
pure virtual

Deallocate memory allocated with allocate()

Parameters
ptrthe pointer returned by allocate()
nthe size of the block pointed to by ptr

Implemented in Botan::Malloc_Allocator, and Botan::Pooling_Allocator.

◆ destroy()

virtual void Botan::Allocator::destroy ( )
inlinevirtual

Shutdown the allocator

Reimplemented in Botan::Pooling_Allocator.

Definition at line 58 of file allocate.h.

58{}

◆ get()

Allocator * Botan::Allocator::get ( bool locking)
static

Acquire a pointer to an allocator

Parameters
lockingis true if the allocator should attempt to secure the memory (eg for using to store keys)
Returns
pointer to an allocator; ownership remains with library, so do not delete

Definition at line 90 of file defalloc.cpp.

91 {
92 std::string type = "";
93 if(!locking)
94 type = "malloc";
95
96 Allocator* alloc = global_state().get_allocator(type);
97 if(alloc)
98 return alloc;
99
100 throw Internal_Error("Couldn't find an allocator to use in get_allocator");
101 }
virtual std::string type() const =0
Allocator * get_allocator(const std::string &name="") const
Definition libstate.cpp:67
Library_State & global_state()
Internal_Error(const std::string &err)
Definition exceptn.h:47

References Botan::Library_State::get_allocator(), Botan::global_state(), Botan::Internal_Error::Internal_Error(), and type().

Referenced by Botan::GMP_Engine::GMP_Engine(), and Botan::MemoryRegion< T >::init().

◆ init()

virtual void Botan::Allocator::init ( )
inlinevirtual

Initialize the allocator

Definition at line 53 of file allocate.h.

53{}

Referenced by Botan::Library_State::add_allocator().

◆ type()

virtual std::string Botan::Allocator::type ( ) const
pure virtual
Returns
name of this allocator type

Implemented in Botan::Locking_Allocator, Botan::Malloc_Allocator, and Botan::MemoryMapping_Allocator.

Referenced by Botan::Library_State::add_allocator(), and get().


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