ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
Gluco::RegionAllocator< T > Class Template Reference

#include <Alloc.h>

Public Types

enum  { Ref_Undef = UINT32_MAX }
 
enum  { Unit_Size = sizeof(uint32_t) }
 
typedef uint32_t Ref
 

Public Member Functions

 RegionAllocator (uint32_t start_cap=1024 *1024)
 
 ~RegionAllocator ()
 
uint32_t size () const
 
uint32_t wasted () const
 
Ref alloc (int size)
 
void free_ (int size)
 
void clear ()
 
T & operator[] (Ref r)
 
const T & operator[] (Ref r) const
 
T * lea (Ref r)
 
const T * lea (Ref r) const
 
Ref ael (const T *t)
 
void moveTo (RegionAllocator &to)
 

Detailed Description

template<class T>
class Gluco::RegionAllocator< T >

Definition at line 35 of file Alloc.h.

Member Typedef Documentation

◆ Ref

template<class T>
typedef uint32_t Gluco::RegionAllocator< T >::Ref

Definition at line 46 of file Alloc.h.

Member Enumeration Documentation

◆ anonymous enum

template<class T>
anonymous enum
Enumerator
Unit_Size 

Definition at line 48 of file Alloc.h.

◆ anonymous enum

template<class T>
anonymous enum
Enumerator
Ref_Undef 

Definition at line 47 of file Alloc.h.

Constructor & Destructor Documentation

◆ RegionAllocator()

template<class T>
Gluco::RegionAllocator< T >::RegionAllocator ( uint32_t start_cap = 1024*1024)
inlineexplicit

Definition at line 50 of file Alloc.h.

50: memory(NULL), sz(0), cap(0), wasted_(0){ capacity(start_cap); }

◆ ~RegionAllocator()

template<class T>
Gluco::RegionAllocator< T >::~RegionAllocator ( )
inline

Definition at line 51 of file Alloc.h.

52 {
53 if (memory != NULL)
54 ::free(memory);
55 }
VOID_HACK free()

Member Function Documentation

◆ ael()

template<class T>
Ref Gluco::RegionAllocator< T >::ael ( const T * t)
inline

Definition at line 71 of file Alloc.h.

71 { assert((void*)t >= (void*)&memory[0] && (void*)t < (void*)&memory[sz-1]);
72 return (Ref)(t - &memory[0]); }
#define assert(ex)
Definition util_old.h:213
Here is the caller graph for this function:

◆ alloc()

template<class T>
RegionAllocator< T >::Ref Gluco::RegionAllocator< T >::alloc ( int size)

Definition at line 114 of file Alloc.h.

115{
116 //printf("ALLOC called (this = %p, size = %d)\n", this, size); fflush(stdout);
117 assert(size > 0);
118 capacity(sz + size);
119
120 uint32_t prev_sz = sz;
121 sz += size;
122
123 // Handle overflow:
124 if (sz < prev_sz)
126
127 return prev_sz;
128}
uint32_t size() const
Definition Alloc.h:58
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

template<class T>
void Gluco::RegionAllocator< T >::clear ( )
inline

Definition at line 63 of file Alloc.h.

63{ sz = 0; wasted_=0; }

◆ free_()

template<class T>
void Gluco::RegionAllocator< T >::free_ ( int size)
inline

Definition at line 62 of file Alloc.h.

62{ wasted_ += size; }
Here is the caller graph for this function:

◆ lea() [1/2]

template<class T>
T * Gluco::RegionAllocator< T >::lea ( Ref r)
inline

Definition at line 69 of file Alloc.h.

69{ assert(r >= 0 && r < sz); return &memory[r]; }
Here is the caller graph for this function:

◆ lea() [2/2]

template<class T>
const T * Gluco::RegionAllocator< T >::lea ( Ref r) const
inline

Definition at line 70 of file Alloc.h.

70{ assert(r >= 0 && r < sz); return &memory[r]; }

◆ moveTo()

template<class T>
void Gluco::RegionAllocator< T >::moveTo ( RegionAllocator< T > & to)
inline

Definition at line 74 of file Alloc.h.

74 {
75 if (to.memory != NULL) ::free(to.memory);
76 to.memory = memory;
77 to.sz = sz;
78 to.cap = cap;
79 to.wasted_ = wasted_;
80
81 memory = NULL;
82 sz = cap = wasted_ = 0;
83 }
Here is the caller graph for this function:

◆ operator[]() [1/2]

template<class T>
T & Gluco::RegionAllocator< T >::operator[] ( Ref r)
inline

Definition at line 66 of file Alloc.h.

66{ assert(r >= 0 && r < sz); return memory[r]; }
Here is the caller graph for this function:

◆ operator[]() [2/2]

template<class T>
const T & Gluco::RegionAllocator< T >::operator[] ( Ref r) const
inline

Definition at line 67 of file Alloc.h.

67{ assert(r >= 0 && r < sz); return memory[r]; }

◆ size()

template<class T>
uint32_t Gluco::RegionAllocator< T >::size ( ) const
inline

Definition at line 58 of file Alloc.h.

58{ return sz; }
Here is the caller graph for this function:

◆ wasted()

template<class T>
uint32_t Gluco::RegionAllocator< T >::wasted ( ) const
inline

Definition at line 59 of file Alloc.h.

59{ return wasted_; }

The documentation for this class was generated from the following file: