ATLAS Offline Software
DataModelTestDataRead/src/AllocTestAuxContainer_v1.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
12 #undef NDEBUG
15 #include "CxxUtils/xmalloc.h"
16 
17 
18 namespace {
19 
20 
27 class TestMemResource
28  : public std::pmr::memory_resource
29 {
30 public:
31  constexpr static size_t MAGIC = 0xdeadbeefcafefeed;
32 
33  virtual void* do_allocate (size_t bytes, std::size_t /*alignment*/) override
34  {
35  size_t* p = reinterpret_cast<size_t*>(CxxUtils::xmalloc (bytes + 2*sizeof(size_t)));
36  p[0] = bytes;
37  p[1] = MAGIC;
38  return p + 2;
39  }
40 
41  virtual void do_deallocate (void* p, [[maybe_unused]] std::size_t bytes, std::size_t /*alignment*/) override
42  {
43  size_t* pp = reinterpret_cast<size_t*>(p);
44  pp -= 2;
45  assert (pp[0] == bytes);
46  assert (pp[1] == MAGIC);
47  free (pp);
48  }
49 
50  virtual bool do_is_equal (const std::pmr::memory_resource& other) const noexcept override
51  {
52  return dynamic_cast<const TestMemResource*> (&other) != nullptr;
53  }
54 };
55 
56 
57 // No state, so thread-safe.
58 static TestMemResource memRes ATLAS_THREAD_SAFE;
59 
60 
61 }
62 
63 
64 namespace DMTest {
65 
66 
68  : xAOD::AuxContainerBase(&memRes)
69 {
70 }
71 
72 
74  : xAOD::AuxContainerBase(),
75  atInt1 (r)
76 {
77 }
78 
79 
80 } // namespace DMTest
beamspotman.r
def r
Definition: beamspotman.py:674
xAOD
ICaloAffectedTool is abstract interface for tools checking if 4 mom is in calo affected region.
Definition: ICaloAffectedTool.h:24
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
AllocTestAuxContainer_v1.h
Testing an xAOD object with a non-standard memory allocator.
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
CxxUtils::xmalloc
void * xmalloc(size_t size)
Trapping version of malloc.
Definition: xmalloc.cxx:31
checker_macros.h
Define macros for attributes used to control the static checker.
DMTest::AllocTestAuxContainer_v1::AllocTestAuxContainer_v1
AllocTestAuxContainer_v1()
Definition: DataModelTestDataRead/src/AllocTestAuxContainer_v1.cxx:67
xmalloc.h
Trapping version of malloc.
DMTest
Definition: B.h:23