#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 *) |
BlockWipedAllocator & | operator= (BlockWipedAllocator const &rh) |
void | registerCache (LocalCache *c) |
Stat | stat () const |
void | wipe (bool force=true) const |
~BlockWipedAllocator () | |
Protected Member Functions | |
BlockWipedAllocator & | me () const |
Private Types | |
typedef std::list< Block > | Blocks |
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 |
Definition at line 23 of file BlockWipedAllocator.h.
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.
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 | ( | ) |
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(), BlockWipedPoolAllocated::operator new(), and SizeBlockWipedAllocated< T >::operator new().
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().
void BlockWipedAllocator::dealloc | ( | void * | p | ) |
Definition at line 51 of file BlockWipedAllocator.cc.
References likely, m_alive, m_maxRecycle, and recycled.
Referenced by BlockWipedAllocated< _bqueue_item< T > >::dealloc(), BlockWipedPoolAllocated::operator delete(), and SizeBlockWipedAllocated< T >::operator delete().
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.
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 BlockWipedPoolAllocated::stat(), BlockWipedAllocated< _bqueue_item< T > >::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(); }
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().