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)
 BlockWipedAllocator (BlockWipedAllocator const &rh)
void clear () const
void dealloc (void *)
BlockWipedAllocatoroperator= (BlockWipedAllocator const &rh)
void registerCache (LocalCache *c)
Stat stat () const
void wipe () const

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)

Private Attributes

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

Detailed Description

Definition at line 17 of file BlockWipedAllocator.h.


Member Typedef Documentation

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

Definition at line 85 of file BlockWipedAllocator.h.

typedef Blocks::const_iterator BlockWipedAllocator::const_iterator [private]

Definition at line 87 of file BlockWipedAllocator.h.

typedef Blocks::iterator BlockWipedAllocator::iterator [private]

Definition at line 86 of file BlockWipedAllocator.h.

typedef unsigned char* BlockWipedAllocator::pointer [private]

Definition at line 84 of file BlockWipedAllocator.h.


Constructor & Destructor Documentation

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

Definition at line 4 of file BlockWipedAllocator.cc.

References wipe().

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

Definition at line 12 of file BlockWipedAllocator.cc.

References wipe().

                                                                       :
  m_typeSize(rh.m_typeSize), m_blockSize(rh.m_blockSize),m_alive(0) {
  wipe();
}

Member Function Documentation

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

Definition at line 41 of file BlockWipedAllocator.cc.

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

Referenced by BlockWipedPool::clear().

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

Definition at line 54 of file BlockWipedAllocator.cc.

Referenced by clear(), and wipe().

                                                    {
  return const_cast<BlockWipedAllocator&>(*this);
}
void BlockWipedAllocator::nextBlock ( bool  advance) [private]

Definition at line 66 of file BlockWipedAllocator.cc.

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

Referenced by alloc(), and wipe().

                                                {
  if (advance) m_current++;
  if (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 17 of file BlockWipedAllocator.cc.

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

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

Definition at line 49 of file BlockWipedAllocator.h.

References localCaches.

                                     {
    localCaches.push_back(c);
  }
BlockWipedAllocator::Stat BlockWipedAllocator::stat ( ) const

Definition at line 58 of file BlockWipedAllocator.cc.

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

Referenced by BlockWipedPoolAllocated::stat(), SizeBlockWipedAllocated< T >::stat(), and BlockWipedAllocated< 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 ( ) const

Definition at line 46 of file BlockWipedAllocator.cc.

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

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

                                     {
  // reset caches
  std::for_each(localCaches.begin(),localCaches.end(),boost::bind(&LocalCache::reset,_1));

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

Member Data Documentation

Definition at line 54 of file BlockWipedAllocator.h.

Referenced by registerCache(), and wipe().

Definition at line 96 of file BlockWipedAllocator.h.

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

Definition at line 94 of file BlockWipedAllocator.h.

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

std::size_t BlockWipedAllocator::m_blockSize [private]

Definition at line 91 of file BlockWipedAllocator.h.

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

Definition at line 93 of file BlockWipedAllocator.h.

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

Definition at line 92 of file BlockWipedAllocator.h.

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

std::size_t BlockWipedAllocator::m_typeSize [private]

Definition at line 90 of file BlockWipedAllocator.h.

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