Botan: Botan::Malloc_Allocator Class Reference

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | List of all members
Botan::Malloc_Allocator Class Reference

`#include <defalloc.h>`

Inheritance diagram for Botan::Malloc_Allocator:

## Public Member Functions
void * | allocate (size_t)
void | deallocate (void *, size_t)
virtual void | destroy ()
virtual void | init ()
std::string | type () const

## Static Public Member Functions
static Allocator * | get (bool locking)

## Detailed Description

Allocator using malloc

Definition at line 18 of file defalloc.h.

## Member Function Documentation

void * Botan::Malloc_Allocator::allocate | ( | size_t | n | ) |
| virtual

Allocate a block of memory

Parameters

  n | how many bytes to allocate

Returns
  pointer to n bytes of memory

Implements Botan::Allocator.

Definition at line 55 of file defalloc.cpp.

56 {
57 void* ptr = do_malloc(n, false);
58 if(!ptr)
59 throw Memory_Exhaustion();
60 return ptr;
61 }

void Botan::Malloc_Allocator::deallocate | ( | void * | ptr,
|  | size_t | n
| ) |  |
| virtual

Deallocate memory allocated with allocate()

Parameters

  ptr | the pointer returned by allocate()
  n | the size of the block pointed to by ptr

Implements Botan::Allocator.

Definition at line 66 of file defalloc.cpp.

67 {
68 do_free(ptr, n, false);
69 }

virtual void Botan::Allocator::destroy | ( |  | ) |
| inlinevirtualinherited

Shutdown the allocator

Reimplemented in Botan::Pooling_Allocator.

Definition at line 58 of file allocate.h.

58 {}

Allocator * Botan::Allocator::get | ( | bool | locking | ) |
| staticinherited

Acquire a pointer to an allocator

Parameters

  locking | is 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.

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

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

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 }
Botan::Global_State_Management::global_state
Library_State & global_state()
Definition: global_state.cpp:32
Botan::Library_State::get_allocator
Allocator * get_allocator(const std::string &name="") const
Definition: libstate.cpp:67
Botan::Allocator::type
virtual std::string type() const =0
alloc
Allocator * alloc
Definition: bzip2.cpp:29

virtual void Botan::Allocator::init | ( |  | ) |
| inlinevirtualinherited

Initialize the allocator

Definition at line 53 of file allocate.h.

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

53 {}

std::string Botan::Malloc_Allocator::type | ( |  | ) | const
| inlinevirtual

Returns
  name of this allocator type

Implements Botan::Allocator.

Definition at line 24 of file defalloc.h.

Referenced by Botan::Allocator::get().

24 { return "malloc"; }

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

- src/alloc/system_alloc/defalloc.h
- src/alloc/system_alloc/defalloc.cpp