ATLAS Offline Software
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
TCS::Heap< T > Class Template Reference

#include <Heap.h>

Collaboration diagram for TCS::Heap< T >:

Classes

class  HeapStructure
 

Public Member Functions

 Heap (const std::string &name, size_t capacity=120)
 
 ~Heap ()
 
void clear ()
 
T * create (const T &obj)
 create an object on the heap More...
 
size_t size () const
 
size_t capacity () const
 

Private Member Functions

void * allocate (size_t size)
 
void deallocate (void *&mem)
 
void extend ()
 

Private Attributes

HeapStructure m_heap
 
std::string m_name {}
 
size_t m_originalCapacity {0}
 

Detailed Description

template<class T>
class TCS::Heap< T >

Definition at line 13 of file Heap.h.

Constructor & Destructor Documentation

◆ Heap()

template<class T >
TCS::Heap< T >::Heap ( const std::string &  name,
size_t  capacity = 120 
)
inline

Definition at line 15 of file Heap.h.

15  :
16  m_name(name),
18  {
20  m_heap.pos = (T*)m_heap.heap;
21  }

◆ ~Heap()

template<class T >
TCS::Heap< T >::~Heap ( )
inline

Definition at line 23 of file Heap.h.

23  {
24  clear();
26  m_heap.heap = nullptr;
27  m_heap.pos = nullptr;
28  }

Member Function Documentation

◆ allocate()

template<class T >
void* TCS::Heap< T >::allocate ( size_t  size)
inlineprivate

Definition at line 80 of file Heap.h.

80  {
81  return ::operator new ( size * sizeof(T) );
82  }

◆ capacity()

template<class T >
size_t TCS::Heap< T >::capacity ( ) const
inline

Definition at line 62 of file Heap.h.

62  {
63  return (m_heap.heapCollection.size() + 1) * m_originalCapacity;
64  }

◆ clear()

template<class T >
void TCS::Heap< T >::clear ( )
inline

Definition at line 32 of file Heap.h.

32  {
33  // destruct objects on the currently active memory block
34  T * p = (T*)m_heap.heap;
35  while(p != m_heap.pos) {
36  (p++)->~T();
37  }
38  m_heap.pos = (T*)m_heap.heap; // reset the position to the beginning of the active memory block
39  // destroy objects on all other memory blocks
40  for(void * heap : m_heap.heapCollection) {
41  T * p = (T*)heap;
42  for(unsigned int t=0; t<m_originalCapacity; ++t)
43  (p++)->~T();
44  deallocate(heap); // destroy other blocks
45  }
46  m_heap.heapCollection.clear(); // clear the collection of memory blocks
47  }

◆ create()

template<class T >
T* TCS::Heap< T >::create ( const T &  obj)
inline

create an object on the heap

Definition at line 50 of file Heap.h.

50  {
51  if( (int)(m_heap.pos - (T*)m_heap.heap) == (int)m_originalCapacity ) {
52  extend();
53  }
54  T* newObject = new(m_heap.pos++) T(obj);
55  return newObject;
56  }

◆ deallocate()

template<class T >
void TCS::Heap< T >::deallocate ( void *&  mem)
inlineprivate

Definition at line 85 of file Heap.h.

85  {
86  ::operator delete ( mem );
87  mem = nullptr;
88  }

◆ extend()

template<class T >
void TCS::Heap< T >::extend ( )
inlineprivate

Definition at line 91 of file Heap.h.

91  {
92  m_heap.heapCollection.push_back(m_heap.heap); // park the old heap which has grown too small
93  m_heap.heap = allocate(m_originalCapacity); // create a new heap the same size as the original one
94  m_heap.pos = (T*)m_heap.heap; // make current position point to it
95  }

◆ size()

template<class T >
size_t TCS::Heap< T >::size ( ) const
inline

Definition at line 58 of file Heap.h.

58  {
59  return (m_heap.pos - (T*)m_heap.heap) + m_heap.heapCollection.size() * m_originalCapacity;
60  }

Member Data Documentation

◆ m_heap

template<class T >
HeapStructure TCS::Heap< T >::m_heap
private

Definition at line 75 of file Heap.h.

◆ m_name

template<class T >
std::string TCS::Heap< T >::m_name {}
private

Definition at line 76 of file Heap.h.

◆ m_originalCapacity

template<class T >
size_t TCS::Heap< T >::m_originalCapacity {0}
private

Definition at line 77 of file Heap.h.


The documentation for this class was generated from the following file:
TCS::Heap::clear
void clear()
Definition: Heap.h:32
TCS::Heap::m_originalCapacity
size_t m_originalCapacity
Definition: Heap.h:77
TCS::Heap::deallocate
void deallocate(void *&mem)
Definition: Heap.h:85
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
TCS::Heap::extend
void extend()
Definition: Heap.h:91
TCS::Heap::HeapStructure::pos
T * pos
Definition: Heap.h:71
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
TCS::Heap::HeapStructure::heapCollection
std::vector< void * > heapCollection
Definition: Heap.h:72
TCS::Heap::m_heap
HeapStructure m_heap
Definition: Heap.h:75
TCS::Heap::capacity
size_t capacity() const
Definition: Heap.h:62
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
TCS::Heap::size
size_t size() const
Definition: Heap.h:58
TCS::Heap::allocate
void * allocate(size_t size)
Definition: Heap.h:80
TCS::Heap::m_name
std::string m_name
Definition: Heap.h:76
TCS::Heap::HeapStructure::heap
void * heap
Definition: Heap.h:70
python.PyAthena.obj
obj
Definition: PyAthena.py:132
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35