MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
maia::alloc Namespace Reference

Functions

void debug (const MString &objectName, const MString &elementsName)
 Debug output for mAlloc. More...
 
void debug (const MString &objectName)
 
void debug_collector (const MString &objectName, const MInt maxSize, const MString &function)
 
void debug_list (const MString &objectName, const MInt maxSize, const MString &function)
 
template<class T >
MInt findAllocatedObject (const T *const a, std::vector< GenericObject * >::iterator &hit)
 Find the allocated object for a given pointer. More...
 
template<class T >
MBool isAllocated (const T *const a)
 Check if the given pointer belongs to an allocated object. More...
 
template<class T >
void checkPointer (const T *const a, const MString objectName, const MString function)
 
template<class T >
void checkPointer (const T *const, const MString &, const MString &)
 
template<class T >
void store_collector (Collector< T > *a, MLong maxSize, const MString &objectName, const MString &functionName)
 
template<class T >
Collector< T > * make_collector (const MLong size, const MInt dummy1, const MInt dummy2, const MInt dummy3, const MInt dummy4)
 
template<class T >
Collector< T > * make_collector (const MLong size, const MInt dimension, const MFloat dummy, const MInt maxNoSets)
 
template<class T >
Collector< T > * make_collector (const MLong size, const MInt dimension, const MInt dummy, const MInt dummy1)
 
template<class T >
Collector< T > * make_collector (const MLong size, const MInt dimension, const MInt distributions, const MInt distributions1, const MInt maxNoSurfaces, const MInt dummy1)
 
template<class T >
Collector< T > * make_collector (const MLong size, const MInt dimension, const MInt distributions)
 
template<class T >
Collector< T > * make_collector (const MLong size, const MInt dimension)
 
template<class T >
Collector< T > * make_collector (const MLong size)
 

Variables

std::vector< GenericObject * > g_allocatedObjects
 
MLong g_allocatedBytes = 0
 
MLong g_maxAllocatedBytes = 0
 

Function Documentation

◆ checkPointer() [1/2]

template<class T >
void maia::alloc::checkPointer ( const T *const  a,
const MString  objectName,
const MString  function 
)
inline

Definition at line 99 of file alloc.h.

99 {
100 if(isAllocated(a)) {
101 std::cerr << "Warning in mAlloc: pointer for object '" << objectName
102 << "' already in list of allocated objects, call mDeallocate before reallocating! " << function
103 << std::endl;
104 } else if(a != nullptr) {
105 std::cerr << "Warning in mAlloc: passed pointer != nullptr for object '" << objectName << "'! " << function
106 << std::endl;
107 }
108}
MBool isAllocated(const T *const a)
Check if the given pointer belongs to an allocated object.
Definition: alloc.h:90
Definition: contexttypes.h:19

◆ checkPointer() [2/2]

template<class T >
void maia::alloc::checkPointer ( const T * const  ,
const MString ,
const MString  
)
inline

Definition at line 111 of file alloc.h.

111{}

◆ debug() [1/2]

void maia::alloc::debug ( const MString objectName)
inline

Definition at line 41 of file alloc.h.

41{ debug(objectName, objectName); }
void debug(const MString &objectName, const MString &elementsName)
Debug output for mAlloc.
Definition: alloc.h:31

◆ debug() [2/2]

void maia::alloc::debug ( const MString objectName,
const MString elementsName 
)
inline

Definition at line 31 of file alloc.h.

31 {
32 MString allocatedObjectName = (objectName == elementsName) ? objectName : objectName + elementsName;
33 typedef std::vector<GenericObject*>::iterator GenericObjIt;
34 for(GenericObjIt i = g_allocatedObjects.begin(); i != g_allocatedObjects.end(); i++) {
35 if((*i)->getName() == allocatedObjectName) {
36 std::cerr << "Warning: object " << objectName << " has already been allocated!" << std::endl;
37 m_log << "Warning: object " << objectName << " has already been allocated!" << std::endl;
38 }
39 }
40}
InfoOutFile m_log
std::basic_string< char > MString
Definition: maiatypes.h:55
std::vector< GenericObject * > g_allocatedObjects

◆ debug_collector()

void maia::alloc::debug_collector ( const MString objectName,
const MInt  maxSize,
const MString function 
)
inline

Definition at line 42 of file alloc.h.

42 {
43 debug(objectName);
44 m_log << "Creating collector '" << objectName << "' with " << maxSize << " elements as requested by " << function
45 << "." << std::endl;
46}

◆ debug_list()

void maia::alloc::debug_list ( const MString objectName,
const MInt  maxSize,
const MString function 
)
inline

Definition at line 48 of file alloc.h.

48 {
49 debug(objectName);
50 m_log << "Creating list '" << objectName << "' with " << maxSize << " elements as requested by " << function << "."
51 << std::endl;
52}

◆ findAllocatedObject()

template<class T >
MInt maia::alloc::findAllocatedObject ( const T *const  a,
std::vector< GenericObject * >::iterator &  hit 
)
inline

Definition at line 63 of file alloc.h.

63 {
64 if(a == nullptr) {
65 return 0;
66 }
67
68 MInt count = 0;
69 for(auto i = g_allocatedObjects.begin(); i != g_allocatedObjects.end(); i++) {
70 auto* object = static_cast<GenericPointer<T>*>(*i);
71 if(static_cast<T*>((*object).getObjectPointer()) == a) {
72 count++;
73 hit = i;
74 if((*object).objectIsArray) {
75 auto j = i + 1;
76 while((j != g_allocatedObjects.end()) && ((*j)->getObjectId() == (*i)->getObjectId())) {
77 count++;
78 j++;
79 }
80 }
81 break;
82 }
83 }
84 return count;
85}
class containing a generic pointer
Definition: genericobject.h:60
int32_t MInt
Definition: maiatypes.h:62

◆ isAllocated()

template<class T >
MBool maia::alloc::isAllocated ( const T *const  a)
inline

Definition at line 90 of file alloc.h.

90 {
91 std::vector<GenericObject*>::iterator hit;
92 const MInt count = findAllocatedObject(a, hit);
93 return (count > 0);
94}
MInt findAllocatedObject(const T *const a, std::vector< GenericObject * >::iterator &hit)
Find the allocated object for a given pointer.
Definition: alloc.h:63

◆ make_collector() [1/7]

template<class T >
Collector< T > * maia::alloc::make_collector ( const MLong  size)
inline

Definition at line 157 of file alloc.h.

157 {
158 return new Collector<T>(size);
159}

◆ make_collector() [2/7]

template<class T >
Collector< T > * maia::alloc::make_collector ( const MLong  size,
const MInt  dimension 
)
inline

Definition at line 153 of file alloc.h.

153 {
154 return new Collector<T>(size, dimension);
155}

◆ make_collector() [3/7]

template<class T >
Collector< T > * maia::alloc::make_collector ( const MLong  size,
const MInt  dimension,
const MFloat  dummy,
const MInt  maxNoSets 
)
inline

Definition at line 132 of file alloc.h.

132 {
133 return new Collector<T>(size, dimension, dummy, maxNoSets);
134}

◆ make_collector() [4/7]

template<class T >
Collector< T > * maia::alloc::make_collector ( const MLong  size,
const MInt  dimension,
const MInt  distributions 
)
inline

Definition at line 149 of file alloc.h.

149 {
150 return new Collector<T>(size, dimension, distributions);
151}

◆ make_collector() [5/7]

template<class T >
Collector< T > * maia::alloc::make_collector ( const MLong  size,
const MInt  dimension,
const MInt  distributions,
const MInt  distributions1,
const MInt  maxNoSurfaces,
const MInt  dummy1 
)
inline

Definition at line 142 of file alloc.h.

143 {
144 return new Collector<T>(size, dimension, distributions, distributions1, maxNoSurfaces, dummy1);
145}

◆ make_collector() [6/7]

template<class T >
Collector< T > * maia::alloc::make_collector ( const MLong  size,
const MInt  dimension,
const MInt  dummy,
const MInt  dummy1 
)
inline

Definition at line 138 of file alloc.h.

138 {
139 return new Collector<T>(size, dimension, dummy, dummy1);
140}

◆ make_collector() [7/7]

template<class T >
Collector< T > * maia::alloc::make_collector ( const MLong  size,
const MInt  dummy1,
const MInt  dummy2,
const MInt  dummy3,
const MInt  dummy4 
)
inline

Definition at line 127 of file alloc.h.

128 {
129 return new Collector<T>(size, dummy1, dummy2, dummy3, dummy4);
130}

◆ store_collector()

template<class T >
void maia::alloc::store_collector ( Collector< T > *  a,
MLong  maxSize,
const MString objectName,
const MString functionName 
)
inline

Definition at line 116 of file alloc.h.

116 {
117 const MLong size = (T::staticElementSize() * (maxSize + 2) * sizeof(char)) + ((maxSize + 1) * sizeof(T));
118 g_allocatedObjects.push_back(new GenericPointer<Collector<T>>(a, objectName, size, functionName, false));
119}
int64_t MLong
Definition: maiatypes.h:64

Variable Documentation

◆ g_allocatedBytes

MLong maia::alloc::g_allocatedBytes = 0

Definition at line 27 of file globalvariables.cpp.

◆ g_allocatedObjects

std::vector< GenericObject * > maia::alloc::g_allocatedObjects

Definition at line 26 of file globalvariables.cpp.

◆ g_maxAllocatedBytes

MLong maia::alloc::g_maxAllocatedBytes = 0

Definition at line 28 of file globalvariables.cpp.