Intel HEXL
Intel Homomorphic Encryption Acceleration Library, accelerating the modular arithmetic operations used in homomorphic encryption.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
allocator.hpp
Go to the documentation of this file.
1 // Copyright (C) 2020-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 
4 #pragma once
5 
6 #include <cstddef>
7 
8 namespace intel {
9 namespace hexl {
10 
12 struct AllocatorBase {
13  virtual ~AllocatorBase() noexcept {}
14 
18  virtual void* allocate(size_t bytes_count) = 0;
19 
23  virtual void deallocate(void* p, size_t n) = 0;
24 };
25 
28 template <class AllocatorImpl>
31  void* allocate(size_t bytes_count) override {
32  return static_cast<AllocatorImpl*>(this)->allocate_impl(bytes_count);
33  }
34 
36  void deallocate(void* p, size_t n) override {
37  static_cast<AllocatorImpl*>(this)->deallocate_impl(p, n);
38  }
39 
40  private:
41  // in case AllocatorImpl doesn't provide implementations, use default null
42  // behavior
43  void* allocate_impl(size_t bytes_count) {
44  HEXL_UNUSED(bytes_count);
45  return nullptr;
46  }
47  void deallocate_impl(void* p, size_t n) {
48  HEXL_UNUSED(p);
49  HEXL_UNUSED(n);
50  }
51 };
52 } // namespace hexl
53 } // namespace intel
Base class for custom memory allocator.
Definition: allocator.hpp:12
virtual void deallocate(void *p, size_t n)=0
Deallocate memory.
Definition: eltwise-add-mod.hpp:8
virtual void * allocate(size_t bytes_count)=0
Allocates byte_count bytes of memory.
void * allocate(size_t bytes_count) override
Override interface and delegate implementation to AllocatorImpl.
Definition: allocator.hpp:31
virtual ~AllocatorBase() noexcept
Definition: allocator.hpp:13
#define HEXL_UNUSED(x)
Definition: defines.hpp:13
Helper memory allocation struct which delegates implementation to AllocatorImpl.
Definition: allocator.hpp:29
void deallocate(void *p, size_t n) override
Override interface and delegate implementation to AllocatorImpl.
Definition: allocator.hpp:36