CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes
BlockWipedAllocator Class Reference

#include <BlockWipedAllocator.h>

Classes

struct  Block
 
struct  LocalCache
 
struct  Stat
 

Public Member Functions

void * alloc ()
 
 BlockWipedAllocator (std::size_t typeSize, std::size_t blockSize, std::size_t maxRecycle)
 
 BlockWipedAllocator (BlockWipedAllocator const &rh)
 
void clear () const
 
void dealloc (void *)
 
BlockWipedAllocatoroperator= (BlockWipedAllocator const &rh)
 
void registerCache (LocalCache *c)
 
Stat stat () const
 
void wipe (bool force=true) const
 
 ~BlockWipedAllocator ()
 

Protected Member Functions

BlockWipedAllocatorme () const
 

Private Types

typedef std::list< BlockBlocks
 
typedef Blocks::const_iterator const_iterator
 
typedef Blocks::iterator iterator
 
typedef unsigned char * pointer
 

Private Member Functions

void nextBlock (bool advance) dso_internal
 

Private Attributes

std::vector< LocalCache * > localCaches
 
int m_alive
 
Blocks m_blocks
 
std::size_t m_blockSize
 
iterator m_current
 
std::size_t m_maxRecycle
 
pointer m_next
 
std::size_t m_typeSize
 
std::vector< void * > recycled
 

Detailed Description

Definition at line 23 of file BlockWipedAllocator.h.

Member Typedef Documentation

Definition at line 94 of file BlockWipedAllocator.h.

typedef Blocks::const_iterator BlockWipedAllocator::const_iterator
private

Definition at line 96 of file BlockWipedAllocator.h.

typedef Blocks::iterator BlockWipedAllocator::iterator
private

Definition at line 95 of file BlockWipedAllocator.h.

typedef unsigned char* BlockWipedAllocator::pointer
private

Definition at line 93 of file BlockWipedAllocator.h.

Constructor & Destructor Documentation

BlockWipedAllocator::BlockWipedAllocator ( std::size_t  typeSize,
std::size_t  blockSize,
std::size_t  maxRecycle 
)

Definition at line 4 of file BlockWipedAllocator.cc.

References m_maxRecycle, recycled, and wipe().

6  :
7  m_typeSize(typeSize), m_blockSize(blockSize), m_maxRecycle(maxRecycle), m_alive(0){
8  // if (typeSize<32) abort(); // throw std::bad_alloc();
9  recycled.reserve(m_maxRecycle);
10  wipe();
11 }
std::vector< void * > recycled
void wipe(bool force=true) const
BlockWipedAllocator::BlockWipedAllocator ( BlockWipedAllocator const &  rh)

Definition at line 14 of file BlockWipedAllocator.cc.

References m_maxRecycle, recycled, and wipe().

14  :
15  m_typeSize(rh.m_typeSize), m_blockSize(rh.m_blockSize), m_maxRecycle(rh.m_maxRecycle), m_alive(0) {
16  recycled.reserve(m_maxRecycle);
17  wipe();
18 }
std::vector< void * > recycled
void wipe(bool force=true) const
BlockWipedAllocator::~BlockWipedAllocator ( )

Definition at line 29 of file BlockWipedAllocator.cc.

References clear().

29  {
30  clear();
31 }

Member Function Documentation

void * BlockWipedAllocator::alloc ( )

Definition at line 36 of file BlockWipedAllocator.cc.

References Association::block, likely, m_alive, BlockWipedAllocator::Block::m_allocated, m_current, BlockWipedAllocator::Block::m_data, m_next, m_typeSize, nextBlock(), recycled, run_regression::ret, and unlikely.

Referenced by BlockWipedAllocated< _bqueue_item< T > >::alloc(), and SizeBlockWipedAllocated< T >::operator new().

36  {
37  m_alive++;
38  if likely(!recycled.empty()) {
39  void * ret = recycled.back();
40  recycled.pop_back();
41  return ret;
42  }
43  void * ret = m_next;
45  Block & block = *m_current;
46  ++block.m_allocated;
47  if unlikely(m_next==(&block.m_data.back())+1) nextBlock(true);
48  return ret;
49 }
std::vector< void * > recycled
#define unlikely(x)
Definition: Likely.h:21
void nextBlock(bool advance) dso_internal
block
Formating index page&#39;s pieces.
Definition: Association.py:232
#define likely(x)
Definition: Likely.h:20
void BlockWipedAllocator::clear ( void  ) const
void BlockWipedAllocator::dealloc ( void *  p)
BlockWipedAllocator & BlockWipedAllocator::me ( ) const
protected

Definition at line 71 of file BlockWipedAllocator.cc.

Referenced by clear(), and wipe().

71  {
72  return const_cast<BlockWipedAllocator&>(*this);
73 }
void BlockWipedAllocator::nextBlock ( bool  advance)
private

Definition at line 83 of file BlockWipedAllocator.cc.

References likely, m_blocks, m_blockSize, m_current, m_next, m_typeSize, and unlikely.

Referenced by alloc(), and wipe().

83  {
84  if likely(advance) m_current++;
85  if unlikely(m_current==m_blocks.end()) {
86  m_blocks.push_back(Block());
87  m_current=m_blocks.end(); --m_current;
88  }
89  m_current->m_data.resize(m_blockSize*m_typeSize);
90  m_current->m_allocated=0;
91  m_next = &(m_current->m_data.front());
92 }
#define unlikely(x)
Definition: Likely.h:21
#define end
Definition: vmac.h:38
#define likely(x)
Definition: Likely.h:20
if(dp >Float(M_PI)) dp-
BlockWipedAllocator & BlockWipedAllocator::operator= ( BlockWipedAllocator const &  rh)

Definition at line 20 of file BlockWipedAllocator.cc.

References m_alive, m_blockSize, m_maxRecycle, m_typeSize, recycled, and wipe().

20  {
21  m_typeSize=rh.m_typeSize; m_blockSize=rh.m_blockSize; m_maxRecycle=rh.m_maxRecycle;
22  recycled.reserve(m_maxRecycle);
23  m_alive=0;
24  wipe();
25  return *this;
26 }
std::vector< void * > recycled
void wipe(bool force=true) const
void BlockWipedAllocator::registerCache ( LocalCache c)
inline

Definition at line 57 of file BlockWipedAllocator.h.

References localCaches.

57  {
58  localCaches.push_back(c);
59  }
std::vector< LocalCache * > localCaches
BlockWipedAllocator::Stat BlockWipedAllocator::stat ( ) const

Definition at line 75 of file BlockWipedAllocator.cc.

References m_alive, m_blocks, m_blockSize, m_current, m_next, m_typeSize, and alignCSCRings::s.

Referenced by BlockWipedPoolAllocated::stat(), BlockWipedAllocated< _bqueue_item< T > >::stat(), and SizeBlockWipedAllocated< T >::stat().

75  {
76  Stat s = { m_typeSize, m_blockSize, (*m_current).m_allocated,
77  (&*(*m_current).m_data.end()-m_next)/m_typeSize,
78  std::distance(const_iterator(m_current),m_blocks.end()),
79  m_blocks.size(), m_alive};
80  return s;
81 }
Blocks::const_iterator const_iterator
void BlockWipedAllocator::wipe ( bool  force = true) const

Definition at line 61 of file BlockWipedAllocator.cc.

References localCaches, m_alive, m_blocks, m_current, me(), nextBlock(), recycled, and BlockWipedAllocator::LocalCache::reset().

Referenced by BlockWipedAllocator(), clear(), operator=(), and BlockWipedPool::wipe().

61  {
62  if (m_alive>0 && !force) return;
63  // reset caches
64  std::for_each(localCaches.begin(),localCaches.end(),boost::bind(&LocalCache::reset,_1));
65 
66  me().m_current=me().m_blocks.begin();
67  me().nextBlock(false);
68  me().recycled.clear();
69 }
std::vector< void * > recycled
std::vector< LocalCache * > localCaches
void nextBlock(bool advance) dso_internal
BlockWipedAllocator & me() const

Member Data Documentation

std::vector<LocalCache*> BlockWipedAllocator::localCaches
private

Definition at line 62 of file BlockWipedAllocator.h.

Referenced by registerCache(), and wipe().

int BlockWipedAllocator::m_alive
private

Definition at line 106 of file BlockWipedAllocator.h.

Referenced by alloc(), dealloc(), operator=(), stat(), and wipe().

Blocks BlockWipedAllocator::m_blocks
private

Definition at line 104 of file BlockWipedAllocator.h.

Referenced by clear(), nextBlock(), stat(), and wipe().

std::size_t BlockWipedAllocator::m_blockSize
private

Definition at line 100 of file BlockWipedAllocator.h.

Referenced by nextBlock(), operator=(), and stat().

iterator BlockWipedAllocator::m_current
private

Definition at line 103 of file BlockWipedAllocator.h.

Referenced by alloc(), nextBlock(), stat(), and wipe().

std::size_t BlockWipedAllocator::m_maxRecycle
private

Definition at line 101 of file BlockWipedAllocator.h.

Referenced by BlockWipedAllocator(), dealloc(), and operator=().

pointer BlockWipedAllocator::m_next
private

Definition at line 102 of file BlockWipedAllocator.h.

Referenced by alloc(), nextBlock(), and stat().

std::size_t BlockWipedAllocator::m_typeSize
private

Definition at line 99 of file BlockWipedAllocator.h.

Referenced by alloc(), nextBlock(), operator=(), and stat().

std::vector<void *> BlockWipedAllocator::recycled
private

Definition at line 63 of file BlockWipedAllocator.h.

Referenced by alloc(), BlockWipedAllocator(), dealloc(), operator=(), and wipe().