Botan 3.7.1
Crypto and TLS for C&
allocator.h
Go to the documentation of this file.
1/*
2* (C) 2023 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_ALLOCATOR_HELPERS_H_
8#define BOTAN_ALLOCATOR_HELPERS_H_
9
10#include <botan/types.h>
11#include <cstring>
12
13namespace Botan {
14
15/*
16* Define BOTAN_MALLOC_FN
17*/
18#if defined(__clang__) || defined(__GNUG__)
19 #define BOTAN_MALLOC_FN __attribute__((malloc))
20#elif defined(_MSC_VER)
21 #define BOTAN_MALLOC_FN __declspec(restrict)
22#else
23 #define BOTAN_MALLOC_FN
24#endif
25
26/**
27* Allocate a memory buffer by some method. This should only be used for
28* primitive types (uint8_t, uint32_t, etc).
29*
30* @param elems the number of elements
31* @param elem_size the size of each element
32* @return pointer to allocated and zeroed memory, or throw std::bad_alloc on failure
33*/
34BOTAN_PUBLIC_API(2, 3) BOTAN_MALLOC_FN void* allocate_memory(size_t elems, size_t elem_size);
35
36/**
37* Free a pointer returned by allocate_memory
38* @param p the pointer returned by allocate_memory
39* @param elems the number of elements, as passed to allocate_memory
40* @param elem_size the size of each element, as passed to allocate_memory
41*/
42BOTAN_PUBLIC_API(2, 3) void deallocate_memory(void* p, size_t elems, size_t elem_size);
43
44/**
45* Ensure the allocator is initialized
46*/
48
53
54} // namespace Botan
55
56#endif
#define BOTAN_MALLOC_FN
Definition allocator.h:23
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:19
#define BOTAN_UNSTABLE_API
Definition api.h:32
int(* final)(unsigned char *, CTX *)
void deallocate_memory(void *p, size_t elems, size_t elem_size)
Definition allocator.cpp:47
void initialize_allocator()
Definition allocator.cpp:63
BOTAN_MALLOC_FN void * allocate_memory(size_t elems, size_t elem_size)
Definition allocator.cpp:20