ArmNN
 24.02
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
armnn::MemorySource::Malloc
@ Malloc
armnn::ICustomAllocator
Custom Allocator interface.
Definition: ICustomAllocator.hpp:16
IgnoreUnused.hpp
armnn::DefaultAllocator
Default Memory Allocator class returned from IBackendInternal::GetDefaultAllocator(MemorySource)
Definition: DefaultAllocator.hpp:17
armnn::DefaultAllocator::GetMemoryRegionAtOffset
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...
Definition: DefaultAllocator.hpp:38
armnn::DefaultAllocator::DefaultAllocator
DefaultAllocator()=default
armnn::DefaultAllocator::allocate
void * allocate(size_t size, size_t alignment=0) override
Interface to be implemented by the child class to allocate bytes.
Definition: DefaultAllocator.hpp:22
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::MemorySource
MemorySource
Define the Memory Source to reduce copies.
Definition: Types.hpp:244
armnn::DefaultAllocator::GetMemorySourceType
armnn::MemorySource GetMemorySourceType() override
Used to specify what type of memory is being allocated by this allocator.
Definition: DefaultAllocator.hpp:33
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::DefaultAllocator::free
void free(void *ptr) override
Interface to be implemented by the child class to free the allocated bytes.
Definition: DefaultAllocator.hpp:28
MemorySources.hpp