ATLAS Offline Software
Loading...
Searching...
No Matches
MonitoredMemoryResource.cxx
Go to the documentation of this file.
1//
2// Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3//
4
5// Local include(s).
7
8namespace AthDevice {
9
11 std::pmr::memory_resource& upstream, IMemoryMonitorSvc& svc,
12 const std::string& component, const std::string& device)
13 : m_upstream(upstream),
14 m_svc(svc),
15 m_component(component),
16 m_device(device) {}
17
19
21 std::size_t alignment) {
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}
32
33void MonitoredMemoryResource::do_deallocate(void* p, std::size_t bytes,
34 std::size_t alignment) {
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}
42
44 const std::pmr::memory_resource& other) const noexcept {
45
46 // Simple "object identity" check.
47 return this == &other;
48}
49
50} // namespace AthDevice
Interface to a service that provides "device memory monitoring".
virtual ~MonitoredMemoryResource()
Destructor.
virtual void * do_allocate(std::size_t bytes, std::size_t alignment) override
Allocate memory from the resource.
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.
virtual bool do_is_equal(const std::pmr::memory_resource &other) const noexcept override
Check if the resource is equal to another resource.
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.
virtual void do_deallocate(void *p, std::size_t bytes, std::size_t alignment) override
Deallocate memory from the resource.
MonitoredMemoryResource(std::pmr::memory_resource &upstream, IMemoryMonitorSvc &svc, const std::string &component, const std::string &device)
Constructor.