ArmNN
 22.11
DefaultAllocator.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <cstddef>
9 #include <memory>
10 #include <armnn/MemorySources.hpp>
12 
13 namespace armnn
14 {
15 
16 /** Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource) */
18 {
19 public:
20  DefaultAllocator() = default;
21 
22  void* allocate(size_t size, size_t alignment = 0) override
23  {
24  IgnoreUnused(alignment);
25  return ::operator new(size_t(size));
26  }
27 
28  void free(void* ptr) override
29  {
30  ::operator delete(ptr);
31  }
32 
34  {
36  }
37 
38  void* GetMemoryRegionAtOffset(void* buffer, size_t offset, size_t alignment = 0) override
39  {
40  IgnoreUnused(alignment);
41  return static_cast<char*>(buffer) + offset;
42  }
43 };
44 
45 } // namespace armnn
Custom Allocator interface.
armnn::MemorySource GetMemorySourceType() override
Used to specify what type of memory is being allocated by this allocator.
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
void * GetMemoryRegionAtOffset(void *buffer, size_t offset, size_t alignment=0) override
Interface that may be implemented to allow retrieval of Memory Region from allocated buffer at a cert...
void free(void *ptr) override
Interface to be implemented by the child class to free the allocated bytes.
Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource) ...
MemorySource
Define the Memory Source to reduce copies.
Definition: Types.hpp:230
void * allocate(size_t size, size_t alignment=0) override
Interface to be implemented by the child class to allocate bytes.