Compute Library
 19.08
MemoryManagerOnDemand Class Reference

On-demand memory manager. More...

#include <MemoryManagerOnDemand.h>

Collaboration diagram for MemoryManagerOnDemand:
[legend]

Public Member Functions

 MemoryManagerOnDemand (std::shared_ptr< ILifetimeManager > lifetime_manager, std::shared_ptr< IPoolManager > pool_manager)
 Default Constructor. More...
 
 MemoryManagerOnDemand (const MemoryManagerOnDemand &)=delete
 Prevent instances of this class to be copy constructed. More...
 
MemoryManagerOnDemandoperator= (const MemoryManagerOnDemand &)=delete
 Prevent instances of this class to be copied. More...
 
 MemoryManagerOnDemand (MemoryManagerOnDemand &&)=default
 Allow instances of this class to be move constructed. More...
 
MemoryManagerOnDemandoperator= (MemoryManagerOnDemand &&)=default
 Allow instances of this class to be moved. More...
 
ILifetimeManagerlifetime_manager () override
 Returns the lifetime manager used by the memory manager. More...
 
IPoolManagerpool_manager () override
 Returns the pool manager used by the memory manager. More...
 
void populate (IAllocator &allocator, size_t num_pools) override
 Populates the pool manager with the given number of pools. More...
 
void clear () override
 Clears the pool manager. More...
 
- Public Member Functions inherited from IMemoryManager
virtual ~IMemoryManager ()=default
 Default virtual destructor. More...
 

Detailed Description

On-demand memory manager.

Definition at line 38 of file MemoryManagerOnDemand.h.

Constructor & Destructor Documentation

◆ MemoryManagerOnDemand() [1/3]

MemoryManagerOnDemand ( std::shared_ptr< ILifetimeManager lifetime_manager,
std::shared_ptr< IPoolManager pool_manager 
)

Default Constructor.

Definition at line 34 of file MemoryManagerOnDemand.cpp.

35  : _lifetime_mgr(std::move(lifetime_manager)), _pool_mgr(std::move(pool_manager))
36 {
37  ARM_COMPUTE_ERROR_ON_MSG(!_lifetime_mgr, "Lifetime manager not specified correctly!");
38  ARM_COMPUTE_ERROR_ON_MSG(!_pool_mgr, "Pool manager not specified correctly!");
39 }
IPoolManager * pool_manager() override
Returns the pool manager used by the memory manager.
ILifetimeManager * lifetime_manager() override
Returns the lifetime manager used by the memory manager.
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328

References ARM_COMPUTE_ERROR_ON_MSG.

◆ MemoryManagerOnDemand() [2/3]

Prevent instances of this class to be copy constructed.

◆ MemoryManagerOnDemand() [3/3]

Allow instances of this class to be move constructed.

Member Function Documentation

◆ clear()

void clear ( )
overridevirtual

Clears the pool manager.

Precondition
All pools must be unoccupied

Implements IMemoryManager.

Definition at line 68 of file MemoryManagerOnDemand.cpp.

69 {
70  ARM_COMPUTE_ERROR_ON_MSG(!_pool_mgr, "Pool manager not specified correctly!");
71  _pool_mgr->clear_pools();
72 }
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328

References ARM_COMPUTE_ERROR_ON_MSG.

◆ lifetime_manager()

ILifetimeManager * lifetime_manager ( )
overridevirtual

Returns the lifetime manager used by the memory manager.

Returns
The lifetime manager

Implements IMemoryManager.

Definition at line 41 of file MemoryManagerOnDemand.cpp.

42 {
43  return _lifetime_mgr.get();
44 }

◆ operator=() [1/2]

MemoryManagerOnDemand& operator= ( const MemoryManagerOnDemand )
delete

Prevent instances of this class to be copied.

◆ operator=() [2/2]

MemoryManagerOnDemand& operator= ( MemoryManagerOnDemand &&  )
default

Allow instances of this class to be moved.

◆ pool_manager()

IPoolManager * pool_manager ( )
overridevirtual

Returns the pool manager used by the memory manager.

Returns
The pool manager

Implements IMemoryManager.

Definition at line 46 of file MemoryManagerOnDemand.cpp.

47 {
48  return _pool_mgr.get();
49 }

◆ populate()

void populate ( IAllocator allocator,
size_t  num_pools 
)
overridevirtual

Populates the pool manager with the given number of pools.

Precondition
Pool manager must be empty
Parameters
[in]allocatorAllocator to use for the backing allocations
[in]num_poolsNumber of pools to create

Implements IMemoryManager.

Definition at line 51 of file MemoryManagerOnDemand.cpp.

52 {
53  ARM_COMPUTE_ERROR_ON(!_lifetime_mgr);
54  ARM_COMPUTE_ERROR_ON(!_pool_mgr);
55  ARM_COMPUTE_ERROR_ON_MSG(!_lifetime_mgr->are_all_finalized(), "All the objects have not been finalized!");
56  ARM_COMPUTE_ERROR_ON_MSG(_pool_mgr->num_pools() != 0, "Pool manager already contains pools!");
57 
58  // Create pools
59  auto pool_template = _lifetime_mgr->create_pool(&allocator);
60  for(int i = num_pools; i > 1; --i)
61  {
62  auto pool = pool_template->duplicate();
63  _pool_mgr->register_pool(std::move(pool));
64  }
65  _pool_mgr->register_pool(std::move(pool_template));
66 }
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
src_target allocator() -> allocate()
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328

References arm_compute::test::validation::allocator(), ARM_COMPUTE_ERROR_ON, and ARM_COMPUTE_ERROR_ON_MSG.


The documentation for this class was generated from the following files: