STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Classes | Public Member Functions | Private Attributes | List of all members
stdext::allocators::cache_chunklist< _Sz, _Nelts > Class Template Reference

Classes

class  _Data_array
 
class  _Data_block
 
struct  _Data_node
 

Public Member Functions

 cache_chunklist ()
 
 ~cache_chunklist () _NOEXCEPT
 
_DECLSPEC_ALLOCATOR voidallocate (size_t _Count)
 
void deallocate (void *_Ptr, size_t)
 
bool equals (const cache_chunklist< _Sz, _Nelts > &) const
 

Private Attributes

_Data_block_List
 
_Data_block_Cached_block
 

Constructor & Destructor Documentation

template<size_t _Sz, size_t _Nelts = 20>
stdext::allocators::cache_chunklist< _Sz, _Nelts >::cache_chunklist ( )
inline
457  : _List(0), _Cached_block(0)
458  { // construct with empty list
459  }
_Data_block * _List
Definition: allocators:635
_Data_block * _Cached_block
Definition: allocators:636
template<size_t _Sz, size_t _Nelts = 20>
stdext::allocators::cache_chunklist< _Sz, _Nelts >::~cache_chunklist ( )
inline
462  { // discard any cached block
463  delete _Cached_block;
464  }
_Data_block * _Cached_block
Definition: allocators:636

Member Function Documentation

template<size_t _Sz, size_t _Nelts = 20>
_DECLSPEC_ALLOCATOR void* stdext::allocators::cache_chunklist< _Sz, _Nelts >::allocate ( size_t  _Count)
inline
467  { // suballocate
468  if (_List == 0)
469  { // no list, allocate new item
470  _List = new _Data_block(_Count);
471  _List->_Next = _List->_Prev = _List;
472  }
473  else if (_List->_Free_count == 0)
474  { // list empty, return cached or allocate
475  _Data_block *_Block;
476  if (_Cached_block != 0)
477  { // return cached
478  _Block = _Cached_block;
479  _Cached_block = 0;
480  }
481  else
482  _Block = new _Data_block(_Count);
483 
484  _Block->_Next = _List->_Next;
485  _Block->_Prev = _List;
486  _Block->_Next->_Prev = _Block;
487  _Block->_Prev->_Next = _Block;
488  _List = _Block;
489  }
490 
491  void *_Res = _List->allocate();
492  if (_List->_Free_count == 0 && _List->_Next != _List)
493  { // unlink head block with no available nodes
494  _List->_Next->_Prev = _List->_Prev;
495  _List->_Prev->_Next = _List->_Next;
496  _List = _List->_Next;
497  }
498  return (_Res);
499  }
_Data_block * _Prev
Definition: allocators:632
unsigned int _Count
Definition: xcomplex:668
int _Free_count
Definition: allocators:631
_Data_block * _List
Definition: allocators:635
_Data_block * _Cached_block
Definition: allocators:636
_Data_block * _Next
Definition: allocators:632
void * allocate()
Definition: allocators:607
template<size_t _Sz, size_t _Nelts = 20>
void stdext::allocators::cache_chunklist< _Sz, _Nelts >::deallocate ( void _Ptr,
size_t   
)
inline
502  { // deallocate node
503  _Data_block *_Block = _Data_block::deallocate(_Ptr);
504  if (_Block == _List->_Prev)
505  ;
506  else if (_Block->_Free_count == 1)
507  { // insert master block before tail block
508  _Data_block *tail = _List->_Prev;
509  tail->_Prev->_Next = _Block;
510  _Block->_Prev = tail->_Prev;
511  tail->_Prev = _Block;
512  _Block->_Next = tail;
513  if (_List->_Free_count == 0)
514  _List = _List->_Next;
515  }
516  else if (_Block->_Free_count == _Nelts)
517  { // unlink and deallocate master block
518  _Block->_Next->_Prev = _Block->_Prev;
519  _Block->_Prev->_Next = _Block->_Next;
520  if (_List == _Block)
521  _List = _List->_Next;
522  if (_Cached_block == 0)
523  _Cached_block = _Block;
524  }
525  }
_Data_block * _Prev
Definition: allocators:632
int _Free_count
Definition: allocators:631
_Data_block * _List
Definition: allocators:635
_Data_block * _Cached_block
Definition: allocators:636
_Data_block * _Next
Definition: allocators:632
static _Data_block * deallocate(void *_Ptr)
Definition: allocators:615
template<size_t _Sz, size_t _Nelts = 20>
bool stdext::allocators::cache_chunklist< _Sz, _Nelts >::equals ( const cache_chunklist< _Sz, _Nelts > &  ) const
inline
528  { // report that caches can share data
529  return (true);
530  }

Member Data Documentation

template<size_t _Sz, size_t _Nelts = 20>
_Data_block* stdext::allocators::cache_chunklist< _Sz, _Nelts >::_Cached_block
private
template<size_t _Sz, size_t _Nelts = 20>
_Data_block* stdext::allocators::cache_chunklist< _Sz, _Nelts >::_List
private

The documentation for this class was generated from the following file: