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
 
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
450  : _List(0), _Cached_block(0)
451  { // construct with empty list
452  }
_Data_block * _List
Definition: allocators:628
_Data_block * _Cached_block
Definition: allocators:629
template<size_t _Sz, size_t _Nelts = 20>
stdext::allocators::cache_chunklist< _Sz, _Nelts >::~cache_chunklist ( )
inline
455  { // discard any cached block
456  delete _Cached_block;
457  }
_Data_block * _Cached_block
Definition: allocators:629

Member Function Documentation

template<size_t _Sz, size_t _Nelts = 20>
void* stdext::allocators::cache_chunklist< _Sz, _Nelts >::allocate ( size_t  _Count)
inline
460  { // suballocate
461  if (_List == 0)
462  { // no list, allocate new item
463  _List = new _Data_block(_Count);
464  _List->_Next = _List->_Prev = _List;
465  }
466  else if (_List->_Free_count == 0)
467  { // list empty, return cached or allocate
468  _Data_block *_Block;
469  if (_Cached_block != 0)
470  { // return cached
471  _Block = _Cached_block;
472  _Cached_block = 0;
473  }
474  else
475  _Block = new _Data_block(_Count);
476 
477  _Block->_Next = _List->_Next;
478  _Block->_Prev = _List;
479  _Block->_Next->_Prev = _Block;
480  _Block->_Prev->_Next = _Block;
481  _List = _Block;
482  }
483 
484  void *_Res = _List->allocate();
485  if (_List->_Free_count == 0 && _List->_Next != _List)
486  { // unlink head block with no available nodes
487  _List->_Next->_Prev = _List->_Prev;
488  _List->_Prev->_Next = _List->_Next;
489  _List = _List->_Next;
490  }
491  return (_Res);
492  }
_Data_block * _Prev
Definition: allocators:625
int _Free_count
Definition: allocators:624
_Data_block * _List
Definition: allocators:628
_Data_block * _Cached_block
Definition: allocators:629
_Data_block * _Next
Definition: allocators:625
void * allocate()
Definition: allocators:600
_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
495  { // deallocate node
496  _Data_block *_Block = _Data_block::deallocate(_Ptr);
497  if (_Block == _List->_Prev)
498  ;
499  else if (_Block->_Free_count == 1)
500  { // insert master block before tail block
501  _Data_block *tail = _List->_Prev;
502  tail->_Prev->_Next = _Block;
503  _Block->_Prev = tail->_Prev;
504  tail->_Prev = _Block;
505  _Block->_Next = tail;
506  if (_List->_Free_count == 0)
507  _List = _List->_Next;
508  }
509  else if (_Block->_Free_count == _Nelts)
510  { // unlink and deallocate master block
511  _Block->_Next->_Prev = _Block->_Prev;
512  _Block->_Prev->_Next = _Block->_Next;
513  if (_List == _Block)
514  _List = _List->_Next;
515  if (_Cached_block == 0)
516  _Cached_block = _Block;
517  }
518  }
_Data_block * _Prev
Definition: allocators:625
int _Free_count
Definition: allocators:624
_Data_block * _List
Definition: allocators:628
_Data_block * _Cached_block
Definition: allocators:629
_Data_block * _Next
Definition: allocators:625
static _Data_block * deallocate(void *_Ptr)
Definition: allocators:608
template<size_t _Sz, size_t _Nelts = 20>
bool stdext::allocators::cache_chunklist< _Sz, _Nelts >::equals ( const cache_chunklist< _Sz, _Nelts > &  ) const
inline
521  { // report that caches can share data
522  return (true);
523  }

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: