Project
Loading...
Searching...
No Matches
ExternalAllocator.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
15
16#ifndef TRACKINGITSU_INCLUDE_EXTERNALALLOCATOR_H_
17#define TRACKINGITSU_INCLUDE_EXTERNALALLOCATOR_H_
18
19#include <memory_resource>
20
21namespace o2::its
22{
23
25{
26 public:
27 virtual void* allocate(size_t) = 0;
28 virtual void deallocate(char*, size_t) = 0;
29};
30
32{
33 public:
34 explicit ExternalAllocatorAdaptor(ExternalAllocator* alloc) : mAlloc(alloc) {}
35
36 protected:
37 void* do_allocate(size_t bytes, size_t alignment) override
38 {
39 void* p = mAlloc->allocate(bytes);
40 if (!p) {
41 throw std::bad_alloc();
42 }
43 return p;
44 }
45
46 void do_deallocate(void* p, size_t bytes, size_t) override
47 {
48 mAlloc->deallocate(static_cast<char*>(p), bytes);
49 }
50
51 bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override
52 {
53 return this == &other;
54 }
55
56 private:
57 ExternalAllocator* mAlloc;
58};
59
60} // namespace o2::its
61
62#endif
void * do_allocate(size_t bytes, size_t alignment) override
ExternalAllocatorAdaptor(ExternalAllocator *alloc)
void do_deallocate(void *p, size_t bytes, size_t) override
bool do_is_equal(const std::pmr::memory_resource &other) const noexcept override
virtual void deallocate(char *, size_t)=0
virtual void * allocate(size_t)=0
VectorOfTObjectPtrs other