CMS 3D CMS Logo

Classes | Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes

BlockWipedAllocator Class Reference

#include <BlockWipedAllocator.h>

List of all members.

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

typedef std::list<Block> BlockWipedAllocator::Blocks [private]

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().

                                                                :
  m_typeSize(typeSize), m_blockSize(blockSize), m_maxRecycle(maxRecycle), m_alive(0){
  //  if (typeSize<32) abort(); // throw std::bad_alloc();
  recycled.reserve(m_maxRecycle);
  wipe();
}
BlockWipedAllocator::BlockWipedAllocator ( BlockWipedAllocator const &  rh)

Definition at line 14 of file BlockWipedAllocator.cc.

References m_maxRecycle, recycled, and wipe().

                                                                       :
  m_typeSize(rh.m_typeSize), m_blockSize(rh.m_blockSize), m_maxRecycle(rh.m_maxRecycle), m_alive(0) {
  recycled.reserve(m_maxRecycle);
  wipe();
}
BlockWipedAllocator::~BlockWipedAllocator ( )

Definition at line 29 of file BlockWipedAllocator.cc.

References clear().

                                          {
  clear();
}

Member Function Documentation

void * BlockWipedAllocator::alloc ( )
void BlockWipedAllocator::clear ( void  ) const

Definition at line 56 of file BlockWipedAllocator.cc.

References m_blocks, me(), and wipe().

Referenced by BlockWipedPool::clear(), and ~BlockWipedAllocator().

                                      {
  me().m_blocks.clear();
  me().wipe();
}
void BlockWipedAllocator::dealloc ( void *  p)
BlockWipedAllocator & BlockWipedAllocator::me ( ) const [protected]

Definition at line 71 of file BlockWipedAllocator.cc.

Referenced by clear(), and wipe().

                                                    {
  return const_cast<BlockWipedAllocator&>(*this);
}
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().

                                                {
  if likely(advance) m_current++;
  if unlikely(m_current==m_blocks.end()) {
    m_blocks.push_back(Block());
    m_current=m_blocks.end(); --m_current;
  }
  m_current->m_data.resize(m_blockSize*m_typeSize);
  m_current->m_allocated=0;
  m_next = &(m_current->m_data.front());
}
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().

                                                                                  {
  m_typeSize=rh.m_typeSize; m_blockSize=rh.m_blockSize; m_maxRecycle=rh.m_maxRecycle;
  recycled.reserve(m_maxRecycle);
  m_alive=0;
  wipe();
  return *this;
}
void BlockWipedAllocator::registerCache ( LocalCache c) [inline]

Definition at line 57 of file BlockWipedAllocator.h.

References localCaches.

                                     {
    localCaches.push_back(c);
  }
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 BlockWipedAllocated< _bqueue_item< T > >::stat(), BlockWipedPoolAllocated::stat(), and SizeBlockWipedAllocated< T >::stat().

                                                        {
  Stat s = { m_typeSize, m_blockSize, (*m_current).m_allocated,
             (&*(*m_current).m_data.end()-m_next)/m_typeSize,
             std::distance(const_iterator(m_current),m_blocks.end()),
             m_blocks.size(), m_alive};
  return s;
}
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().

                                               {
  if (m_alive>0 && !force) return;
  // reset caches
  std::for_each(localCaches.begin(),localCaches.end(),boost::bind(&LocalCache::reset,_1));

  me().m_current=me().m_blocks.begin();
  me().nextBlock(false);
  me().recycled.clear();
}

Member Data Documentation

Definition at line 62 of file BlockWipedAllocator.h.

Referenced by registerCache(), and wipe().

Definition at line 106 of file BlockWipedAllocator.h.

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

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().

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=().

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().