MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
genericobject.h
Go to the documentation of this file.
1// Copyright (C) 2024 The m-AIA AUTHORS
2//
3// This file is part of m-AIA (https://git.rwth-aachen.de/aia/m-AIA/m-AIA)
4//
5// SPDX-License-Identifier: LGPL-3.0-only
6
7#ifndef MAIA_GENERIC_OBJECT_H_
8#define MAIA_GENERIC_OBJECT_H_
9
10#include "IO/infoout.h"
11#include "UTIL/functions.h"
12#include "globalvariables.h"
13
14#ifdef MAIA_EXTRA_DEBUG
15#include <typeinfo>
16#endif
17
23void printAllocatedMemory(const MLong oldAllocatedBytes, const MString& solverName, const MPI_Comm comm);
24
31
38 public:
40 MString& getName() { return objectName; }
41#ifdef MAIA_EXTRA_DEBUG
44#endif
47 MInt& getObjectId() { return objectId; }
50 virtual ~GenericObject() {}
51 MBool operator<(GenericObject otherObject) { return (elementSize < otherObject.elementSize); }
52};
53
59template <typename T>
61 private:
63
64 public:
66 GenericPointer(T* const& t, MString oName, MLong size, MString function, MBool isArray, MBool isNewObject = true);
69};
70
71template <class T>
74#ifdef MAIA_EXTRA_DEBUG
75 function
76#endif
77 ,
78 MBool isArray, MBool isNewObject)
79 : objectPointer(t), objectIsArray(isArray) {
80 using namespace maia::alloc;
81 objectName = oName;
82#ifdef MAIA_EXTRA_DEBUG
83 callingFunction = function;
84#endif
85 elementSize = size;
86 if(isNewObject) {
89 } else
91 g_allocatedBytes += size;
92 g_maxAllocatedBytes = mMax(g_allocatedBytes, g_maxAllocatedBytes);
93}
94
95template <class T>
97 maia::alloc::g_allocatedBytes -= elementSize;
98#ifdef MAIA_EXTRA_DEBUG
99 m_log.precision(2);
100 m_log << "deleting object " << objectName << " (size: " << getMemorySize(elementSize)
101 << ", address: " << objectPointer << ", type: " << typeid(objectPointer).name()
102 << ", isArray: " << objectIsArray << ", called by " << callingFunction << ")...";
103 m_log.flush();
104#endif
105 if(objectPointer) {
106 if(objectIsArray)
107 delete[] objectPointer;
108 else
109 delete objectPointer;
110 objectPointer = nullptr;
111 }
112#ifdef MAIA_EXTRA_DEBUG
113 m_log << "ok" << std::endl;
114#endif
115}
116#endif
class containing a generic object
Definition: genericobject.h:37
MString callingFunction
Definition: genericobject.h:42
MLong & getElementSize()
Definition: genericobject.h:49
MString objectName
Definition: genericobject.h:39
static MInt objectCounter
Variables to initialize:
Definition: genericobject.h:45
MString & getName()
Definition: genericobject.h:40
MBool operator<(GenericObject otherObject)
Definition: genericobject.h:51
virtual ~GenericObject()
Definition: genericobject.h:50
MString & getCallingFunction()
Definition: genericobject.h:43
MInt & getObjectId()
Definition: genericobject.h:47
class containing a generic pointer
Definition: genericobject.h:60
GenericPointer(T *const &t, MString oName, MLong size, MString function, MBool isArray, MBool isNewObject=true)
Definition: genericobject.h:72
T * getObjectPointer()
Definition: genericobject.h:67
constexpr T mMax(const T &x, const T &y)
Definition: functions.h:94
MString getMemorySize(MLong noBytes)
Returns memory size in KB, MB or GB.
void printAllocatedMemory(const MLong oldAllocatedBytes, const MString &solverName, const MPI_Comm comm)
Prints currently allocated memory.
InfoOutFile m_log
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
int64_t MLong
Definition: maiatypes.h:64
bool MBool
Definition: maiatypes.h:58
MLong g_allocatedBytes