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
461  : _List(0), _Cached_block(0)
462  { // construct with empty list
463  }
_Data_block * _List
Definition: allocators:639
_Data_block * _Cached_block
Definition: allocators:640
template<size_t _Sz, size_t _Nelts = 20>
stdext::allocators::cache_chunklist< _Sz, _Nelts >::~cache_chunklist ( )
inline
466  { // discard any cached block
467  delete _Cached_block;
468  }
_Data_block * _Cached_block
Definition: allocators:640

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
471  { // suballocate
472  if (_List == 0)
473  { // no list, allocate new item
474  _List = new _Data_block(_Count);
475  _List->_Next = _List->_Prev = _List;
476  }
477  else if (_List->_Free_count == 0)
478  { // list empty, return cached or allocate
479  _Data_block *_Block;
480  if (_Cached_block != 0)
481  { // return cached
482  _Block = _Cached_block;
483  _Cached_block = 0;
484  }
485  else
486  _Block = new _Data_block(_Count);
487 
488  _Block->_Next = _List->_Next;
489  _Block->_Prev = _List;
490  _Block->_Next->_Prev = _Block;
491  _Block->_Prev->_Next = _Block;
492  _List = _Block;
493  }
494 
495  void *_Res = _List->allocate();
496  if (_List->_Free_count == 0 && _List->_Next != _List)
497  { // unlink head block with no available nodes
498  _List->_Next->_Prev = _List->_Prev;
499  _List->_Prev->_Next = _List->_Next;
500  _List = _List->_Next;
501  }
502  return (_Res);
503  }
_Data_block * _Prev
Definition: allocators:636
int _Free_count
Definition: allocators:635
_Data_block * _List
Definition: allocators:639
_Data_block * _Cached_block
Definition: allocators:640
_Data_block * _Next
Definition: allocators:636
void * allocate()
Definition: allocators:611
_Diff _Count
Definition: algorithm:1941
template<size_t _Sz, size_t _Nelts = 20>
void stdext::allocators::cache_chunklist< _Sz, _Nelts >::deallocate ( void _Ptr,
size_t   
)
inline
506  { // deallocate node
507  _Data_block *_Block = _Data_block::deallocate(_Ptr);
508  if (_Block == _List->_Prev)
509  ;
510  else if (_Block->_Free_count == 1)
511  { // insert master block before tail block
512  _Data_block *tail = _List->_Prev;
513  tail->_Prev->_Next = _Block;
514  _Block->_Prev = tail->_Prev;
515  tail->_Prev = _Block;
516  _Block->_Next = tail;
517  if (_List->_Free_count == 0)
518  _List = _List->_Next;
519  }
520  else if (_Block->_Free_count == _Nelts)
521  { // unlink and deallocate master block
522  _Block->_Next->_Prev = _Block->_Prev;
523  _Block->_Prev->_Next = _Block->_Next;
524  if (_List == _Block)
525  _List = _List->_Next;
526  if (_Cached_block == 0)
527  _Cached_block = _Block;
528  }
529  }
_Data_block * _Prev
Definition: allocators:636
int _Free_count
Definition: allocators:635
_Data_block * _List
Definition: allocators:639
_Data_block * _Cached_block
Definition: allocators:640
_Data_block * _Next
Definition: allocators:636
static _Data_block * deallocate(void *_Ptr)
Definition: allocators:619
template<size_t _Sz, size_t _Nelts = 20>
bool stdext::allocators::cache_chunklist< _Sz, _Nelts >::equals ( const cache_chunklist< _Sz, _Nelts > &  ) const
inline
532  { // report that caches can share data
533  return (true);
534  }

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: