8#ifndef INCLUDED_BSLSTL_SIMPLEPOOL
9#define INCLUDED_BSLSTL_SIMPLEPOOL
239#include <bslscm_version.h>
267template <
class ALLOCATOR>
293template <
class VALUE,
class ALLOCATOR>
299 enum { k_MAX_BLOCKS_PER_CHUNK = 32 };
309 char d_size[
sizeof(VALUE)];
324 typename Types::AllocatorTraits::size_type d_numBytes;
332 {
return reinterpret_cast<Block *
>(
this + 1); }
353 Chunk *d_chunkList_p;
357 int d_blocksPerChunk;
371 Chunk *allocateChunk(std::size_t numBlocks);
377 void deallocateChunk(Chunk *chunk_p);
485template <
class VALUE,
class ALLOCATOR>
489 std::size_t numBytes =
sizeof(Chunk) +
sizeof(Block) * numBlocks;
500 chunkPtr->d_info.d_next_p = d_chunkList_p;
501 chunkPtr->d_info.d_numBytes = numBytes;
502 d_chunkList_p = chunkPtr;
507template <
class VALUE,
class ALLOCATOR>
509SimplePool<VALUE, ALLOCATOR>::deallocateChunk(Chunk *chunk_p)
511 std::size_t numBytes = chunk_p->d_info.d_numBytes;
515 numBytes, alignment);
518template <
class VALUE,
class ALLOCATOR>
520void SimplePool<VALUE, ALLOCATOR>::replenish()
524 if (d_blocksPerChunk < k_MAX_BLOCKS_PER_CHUNK) {
525 d_blocksPerChunk *= 2;
530template <
class VALUE,
class ALLOCATOR>
540template <
class VALUE,
class ALLOCATOR>
545, d_chunkList_p(
bslmf::MovableRefUtil::access(original).d_chunkList_p)
546, d_freeList_p(
bslmf::MovableRefUtil::access(original).d_freeList_p)
547, d_blocksPerChunk(
bslmf::MovableRefUtil::access(original).d_blocksPerChunk)
550 lvalue.d_chunkList_p = 0;
551 lvalue.d_freeList_p = 0;
552 lvalue.d_blocksPerChunk = 1;
555template <
class VALUE,
class ALLOCATOR>
563template <
class VALUE,
class ALLOCATOR>
574 d_chunkList_p = lvalue.d_chunkList_p;
575 d_freeList_p = lvalue.d_freeList_p;
576 d_blocksPerChunk = lvalue.d_blocksPerChunk;
578 lvalue.d_chunkList_p = 0;
579 lvalue.d_freeList_p = 0;
580 lvalue.d_blocksPerChunk = 1;
583template <
class VALUE,
class ALLOCATOR>
591template <
class VALUE,
class ALLOCATOR>
598 VALUE *block =
reinterpret_cast<VALUE *
>(d_freeList_p);
599 d_freeList_p = d_freeList_p->d_next_p;
603template <
class VALUE,
class ALLOCATOR>
609 reinterpret_cast<Block *
>(address)->d_next_p = d_freeList_p;
610 d_freeList_p =
reinterpret_cast<Block *
>(address);
613template <
class VALUE,
class ALLOCATOR>
619 std::swap(d_blocksPerChunk, other.d_blocksPerChunk);
620 std::swap(d_freeList_p, other.d_freeList_p);
621 std::swap(d_chunkList_p, other.d_chunkList_p);
624template <
class VALUE,
class ALLOCATOR>
632template <
class VALUE,
class ALLOCATOR>
644 AllocTraits::propagate_on_container_copy_assignment::value ||
645 AllocTraits::propagate_on_container_move_assignment::value ||
646 AllocTraits::propagate_on_container_swap::value> Propagate;
649 using BloombergLP::bslma::AllocatorUtil;
650 AllocatorUtil::swap(&this->allocator(), &other.
allocator(), Propagate());
651 swap(d_blocksPerChunk, other.d_blocksPerChunk);
652 swap(d_freeList_p, other.d_freeList_p);
653 swap(d_chunkList_p, other.d_chunkList_p);
656template <
class VALUE,
class ALLOCATOR>
661 Block *begin = allocateChunk(numBlocks)->firstBlock();
662 Block *end = begin + numBlocks - 1;
665 for (Block *p = begin; p < end; ++p) {
668 end->d_next_p = d_freeList_p;
669 d_freeList_p = begin;
672template <
class VALUE,
class ALLOCATOR>
675 while (d_chunkList_p) {
676 Chunk *lastChunk = d_chunkList_p;
677 d_chunkList_p = d_chunkList_p->d_info.d_next_p;
678 deallocateChunk(lastChunk);
685template <
class VALUE,
class ALLOCATOR>
693template <
class VALUE,
class ALLOCATOR>
Definition bslmf_movableref.h:752
Definition bslstl_simplepool.h:294
void release()
Relinquish all memory currently allocated via this pool object.
Definition bslstl_simplepool.h:673
Types::AllocatorType AllocatorType
Definition bslstl_simplepool.h:343
void adopt(bslmf::MovableRef< SimplePool > pool)
Definition bslstl_simplepool.h:566
bool hasFreeBlocks() const
Definition bslstl_simplepool.h:695
const AllocatorType & allocator() const
Definition bslstl_simplepool.h:688
void quickSwapExchangeAllocators(SimplePool &other)
Definition bslstl_simplepool.h:634
VALUE ValueType
Alias for the parameterized type VALUE.
Definition bslstl_simplepool.h:339
void deallocate(void *address)
Definition bslstl_simplepool.h:605
AllocatorType & allocator()
Definition bslstl_simplepool.h:586
AllocatorTraits::size_type size_type
Definition bslstl_simplepool.h:349
~SimplePool()
Definition bslstl_simplepool.h:557
SimplePool(const ALLOCATOR &allocator)
Definition bslstl_simplepool.h:532
void quickSwapRetainAllocators(SimplePool &other)
Definition bslstl_simplepool.h:626
void reserve(size_type numBlocks)
Definition bslstl_simplepool.h:657
void swap(SimplePool &other)
Definition bslstl_simplepool.h:615
VALUE * allocate()
Definition bslstl_simplepool.h:593
SimplePool(bslmf::MovableRef< SimplePool > original)
Definition bslstl_simplepool.h:542
Types::AllocatorTraits AllocatorTraits
Definition bslstl_simplepool.h:347
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1976
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1917
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
int reserve(TYPE *array, int numElements)
Definition bdlbb_blob.h:579
Definition bslstl_algorithm.h:84
Definition bslma_allocatortraits.h:1089
Definition bslmf_integralconstant.h:261
static AllocatorUtil_Traits< t_ALLOCATOR >::void_pointer allocateBytes(const t_ALLOCATOR &allocator, std::size_t nbytes, std::size_t alignment=0)
Definition bslma_allocatorutil.h:886
static void deallocateBytes(const t_ALLOCATOR &allocator, typename AllocatorUtil_Traits< t_ALLOCATOR >::void_pointer p, std::size_t nbytes, std::size_t alignment=0)
Definition bslma_allocatorutil.h:930
static t_TYPE & access(t_TYPE &ref) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1039
Definition bsls_alignmentfromtype.h:378
AlignmentToType< VALUE >::Type Type
Definition bsls_alignmentfromtype.h:388
std::size_t UintPtr
Definition bsls_types.h:128
Definition bslstl_simplepool.h:268
AllocatorTraits::allocator_type AllocatorType
Definition bslstl_simplepool.h:277
bsl::allocator_traits< ALLOCATOR >::template rebind_traits< bsls::AlignmentUtil::MaxAlignedType > AllocatorTraits
Definition bslstl_simplepool.h:273