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

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

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

Definition at line 12 of file BlockWipedAllocator.cc.

References wipe().

12  :
13  m_typeSize(rh.m_typeSize), m_blockSize(rh.m_blockSize),m_alive(0) {
14  wipe();
15 }

Member Function Documentation

void * BlockWipedAllocator::alloc ( )
void BlockWipedAllocator::clear ( void  ) const
void BlockWipedAllocator::dealloc ( void *  )
BlockWipedAllocator & BlockWipedAllocator::me ( ) const
protected

Definition at line 54 of file BlockWipedAllocator.cc.

Referenced by clear(), and wipe().

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

66  {
67  if (advance) m_current++;
68  if (m_current==m_blocks.end()) {
69  m_blocks.push_back(Block());
70  m_current=m_blocks.end(); --m_current;
71  }
72  m_current->m_data.resize(m_blockSize*m_typeSize);
73  m_current->m_allocated=0;
74  m_next = &(m_current->m_data.front());
75 }
BlockWipedAllocator & BlockWipedAllocator::operator= ( BlockWipedAllocator const &  rh)

Definition at line 17 of file BlockWipedAllocator.cc.

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

17  {
18  m_typeSize=rh.m_typeSize; m_blockSize=rh.m_blockSize;
19  m_alive=0;
20  wipe();
21  return *this;
22 }
void BlockWipedAllocator::registerCache ( LocalCache c)
inline

Definition at line 49 of file BlockWipedAllocator.h.

References localCaches.

49  {
50  localCaches.push_back(c);
51  }
std::vector< LocalCache * > localCaches
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(), BlockWipedAllocated< T >::stat(), and SizeBlockWipedAllocated< T >::stat().

58  {
59  Stat s = { m_typeSize, m_blockSize, (*m_current).m_allocated,
60  (&*(*m_current).m_data.end()-m_next)/m_typeSize,
61  std::distance(const_iterator(m_current),m_blocks.end()),
62  m_blocks.size(), m_alive};
63  return s;
64 }
Blocks::const_iterator const_iterator
string s
Definition: asciidump.py:422
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().

46  {
47  // reset caches
48  std::for_each(localCaches.begin(),localCaches.end(),boost::bind(&LocalCache::reset,_1));
49 
50  me().m_current=me().m_blocks.begin();
51  me().nextBlock(false);
52 }
std::vector< LocalCache * > localCaches
BlockWipedAllocator & me() const
void nextBlock(bool advance)

Member Data Documentation

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

Definition at line 54 of file BlockWipedAllocator.h.

Referenced by registerCache(), and wipe().

int BlockWipedAllocator::m_alive
private

Definition at line 96 of file BlockWipedAllocator.h.

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

Blocks BlockWipedAllocator::m_blocks
private

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

iterator BlockWipedAllocator::m_current
private

Definition at line 93 of file BlockWipedAllocator.h.

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

pointer BlockWipedAllocator::m_next
private

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