ArmNN
 22.05
MockMemoryManager.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
8 namespace armnn
9 {
10 
12 {}
13 
15 {}
16 
18 {
19  if (!m_FreePools.empty())
20  {
21  Pool* res = m_FreePools.back();
22  m_FreePools.pop_back();
23  res->Reserve(numBytes);
24  return res;
25  }
26  else
27  {
28  m_Pools.push_front(Pool(numBytes));
29  return &m_Pools.front();
30  }
31 }
32 
34 {
35  m_FreePools.push_back(pool);
36 }
37 
39 {
40  return pool->GetPointer();
41 }
42 
44 {
45  for (Pool& pool : m_Pools)
46  {
47  pool.Acquire();
48  }
49 }
50 
52 {
53  for (Pool& pool : m_Pools)
54  {
55  pool.Release();
56  }
57 }
58 
59 MockMemoryManager::Pool::Pool(unsigned int numBytes)
60  : m_Size(numBytes)
61  , m_Pointer(nullptr)
62 {}
63 
65 {
66  if (m_Pointer)
67  {
68  Release();
69  }
70 }
71 
73 {
74  return m_Pointer;
75 }
76 
77 void MockMemoryManager::Pool::Reserve(unsigned int numBytes)
78 {
79  m_Size = std::max(m_Size, numBytes);
80 }
81 
83 {
84  m_Pointer = ::operator new(size_t(m_Size));
85 }
86 
88 {
89  ::operator delete(m_Pointer);
90  m_Pointer = nullptr;
91 }
92 
93 } // namespace armnn
void Reserve(unsigned int numBytes)
Copyright (c) 2021 ARM Limited and Contributors.
void * GetPointer(Pool *pool)
Pool * Manage(unsigned int numBytes)