Botan  1.10.9
allocate.h
Go to the documentation of this file.
1 /*
2 * Allocator
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7 
8 #ifndef BOTAN_ALLOCATOR_H__
9 #define BOTAN_ALLOCATOR_H__
10 
11 #include <botan/types.h>
12 #include <string>
13 
14 namespace Botan {
15 
16 /**
17 * Allocator Interface
18 */
19 class BOTAN_DLL Allocator
20  {
21  public:
22  /**
23  * Acquire a pointer to an allocator
24  * @param locking is true if the allocator should attempt to
25  * secure the memory (eg for using to store keys)
26  * @return pointer to an allocator; ownership remains with library,
27  * so do not delete
28  */
29  static Allocator* get(bool locking);
30 
31  /**
32  * Allocate a block of memory
33  * @param n how many bytes to allocate
34  * @return pointer to n bytes of memory
35  */
36  virtual void* allocate(size_t n) = 0;
37 
38  /**
39  * Deallocate memory allocated with allocate()
40  * @param ptr the pointer returned by allocate()
41  * @param n the size of the block pointed to by ptr
42  */
43  virtual void deallocate(void* ptr, size_t n) = 0;
44 
45  /**
46  * @return name of this allocator type
47  */
48  virtual std::string type() const = 0;
49 
50  /**
51  * Initialize the allocator
52  */
53  virtual void init() {}
54 
55  /**
56  * Shutdown the allocator
57  */
58  virtual void destroy() {}
59 
60  virtual ~Allocator() {}
61  };
62 
63 }
64 
65 #endif
BigInt n
Definition: numthry.cpp:26
virtual void destroy()
Definition: allocate.h:58
virtual void init()
Definition: allocate.h:53
virtual ~Allocator()
Definition: allocate.h:60