ATLAS Offline Software
Loading...
Searching...
No Matches
AthDevice::MonitoredMemoryResource Class Reference

Memory resource that monitors memory allocations and deallocations. More...

#include <MonitoredMemoryResource.h>

Inheritance diagram for AthDevice::MonitoredMemoryResource:
Collaboration diagram for AthDevice::MonitoredMemoryResource:

Public Member Functions

 MonitoredMemoryResource (std::pmr::memory_resource &upstream, IMemoryMonitorSvc &svc, const std::string &component, const std::string &device)
 Constructor.
virtual ~MonitoredMemoryResource ()
 Destructor.

Private Member Functions

Functions inherited from @c std::pmr::memory_resource
virtual void * do_allocate (std::size_t bytes, std::size_t alignment) override
 Allocate memory from the resource.
virtual void do_deallocate (void *p, std::size_t bytes, std::size_t alignment) override
 Deallocate memory from the resource.
virtual bool do_is_equal (const std::pmr::memory_resource &other) const noexcept override
 Check if the resource is equal to another resource.

Private Attributes

Variables used to monitor the memory allocations/deallocations
std::reference_wrapper< std::pmr::memory_resource > m_upstream
 The upstream memory resource to which the allocations are forwarded.
std::reference_wrapper< IMemoryMonitorSvc > m_svc
 The service used to monitor the memory allocations/deallocations.
std::string m_component
 The name of the component that is using this memory resource.
std::string m_device
 The name of the device for which the memory resource is provided.

Detailed Description

Memory resource that monitors memory allocations and deallocations.

It's an Athena specific wrapper around an upstream memory resource, which reports each of its memory (de)allocations to an IMemoryMonitorSvc service.

Definition at line 22 of file MonitoredMemoryResource.h.

Constructor & Destructor Documentation

◆ MonitoredMemoryResource()

AthDevice::MonitoredMemoryResource::MonitoredMemoryResource ( std::pmr::memory_resource & upstream,
IMemoryMonitorSvc & svc,
const std::string & component,
const std::string & device )

Constructor.

Definition at line 10 of file MonitoredMemoryResource.cxx.

13 : m_upstream(upstream),
14 m_svc(svc),
15 m_component(component),
16 m_device(device) {}
std::reference_wrapper< std::pmr::memory_resource > m_upstream
The upstream memory resource to which the allocations are forwarded.
std::string m_device
The name of the device for which the memory resource is provided.
std::reference_wrapper< IMemoryMonitorSvc > m_svc
The service used to monitor the memory allocations/deallocations.
std::string m_component
The name of the component that is using this memory resource.

◆ ~MonitoredMemoryResource()

AthDevice::MonitoredMemoryResource::~MonitoredMemoryResource ( )
virtualdefault

Destructor.

Member Function Documentation

◆ do_allocate()

void * AthDevice::MonitoredMemoryResource::do_allocate ( std::size_t bytes,
std::size_t alignment )
overrideprivatevirtual

Allocate memory from the resource.

Definition at line 20 of file MonitoredMemoryResource.cxx.

21 {
22
23 // Forward the allocation to the upstream memory resource.
24 void* result = m_upstream.get().allocate(bytes, alignment);
25
26 // Notify the service that a memory allocation has been made.
27 m_svc.get().memoryAllocated(m_component, m_device, bytes);
28
29 // Return the pointer to the allocated memory.
30 return result;
31}

◆ do_deallocate()

void AthDevice::MonitoredMemoryResource::do_deallocate ( void * p,
std::size_t bytes,
std::size_t alignment )
overrideprivatevirtual

Deallocate memory from the resource.

Definition at line 33 of file MonitoredMemoryResource.cxx.

34 {
35
36 // Forward the deallocation to the upstream memory resource.
37 m_upstream.get().deallocate(p, bytes, alignment);
38
39 // Notify the service that a memory deallocation has been made.
40 m_svc.get().memoryDeallocated(m_component, m_device, bytes);
41}

◆ do_is_equal()

bool AthDevice::MonitoredMemoryResource::do_is_equal ( const std::pmr::memory_resource & other) const
overrideprivatevirtualnoexcept

Check if the resource is equal to another resource.

Definition at line 43 of file MonitoredMemoryResource.cxx.

44 {
45
46 // Simple "object identity" check.
47 return this == &other;
48}

Member Data Documentation

◆ m_component

std::string AthDevice::MonitoredMemoryResource::m_component
private

The name of the component that is using this memory resource.

Definition at line 57 of file MonitoredMemoryResource.h.

◆ m_device

std::string AthDevice::MonitoredMemoryResource::m_device
private

The name of the device for which the memory resource is provided.

Definition at line 59 of file MonitoredMemoryResource.h.

◆ m_svc

std::reference_wrapper<IMemoryMonitorSvc> AthDevice::MonitoredMemoryResource::m_svc
private

The service used to monitor the memory allocations/deallocations.

Definition at line 55 of file MonitoredMemoryResource.h.

◆ m_upstream

std::reference_wrapper<std::pmr::memory_resource> AthDevice::MonitoredMemoryResource::m_upstream
private

The upstream memory resource to which the allocations are forwarded.

Definition at line 53 of file MonitoredMemoryResource.h.


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