8#ifndef INCLUDED_BSLSTL_SIMPLEPOOL
9#define INCLUDED_BSLSTL_SIMPLEPOOL
239#include <bslscm_version.h>
265template <
class ALLOCATOR>
291template <
class VALUE,
class ALLOCATOR>
297 enum { k_MAX_BLOCKS_PER_CHUNK = 32 };
307 char d_size[
sizeof(VALUE)];
322 typename Types::AllocatorTraits::size_type d_numBytes;
330 {
return reinterpret_cast<Block *
>(
this + 1); }
351 Chunk *d_chunkList_p;
355 int d_blocksPerChunk;
369 Chunk *allocateChunk(std::size_t numBlocks);
374 void deallocateChunk(Chunk *chunk_p);
472template <
class VALUE,
class ALLOCATOR>
476 std::size_t numBytes =
sizeof(Chunk) +
sizeof(Block) * numBlocks;
487 chunkPtr->d_info.d_next_p = d_chunkList_p;
488 chunkPtr->d_info.d_numBytes = numBytes;
489 d_chunkList_p = chunkPtr;
494template <
class VALUE,
class ALLOCATOR>
496SimplePool<VALUE, ALLOCATOR>::deallocateChunk(Chunk *chunk_p)
498 std::size_t numBytes = chunk_p->d_info.d_numBytes;
502 numBytes, alignment);
505template <
class VALUE,
class ALLOCATOR>
507void SimplePool<VALUE, ALLOCATOR>::replenish()
509 reserve(d_blocksPerChunk);
511 if (d_blocksPerChunk < k_MAX_BLOCKS_PER_CHUNK) {
512 d_blocksPerChunk *= 2;
517template <
class VALUE,
class ALLOCATOR>
527template <
class VALUE,
class ALLOCATOR>
532, d_chunkList_p(
bslmf::MovableRefUtil::access(original).d_chunkList_p)
533, d_freeList_p(
bslmf::MovableRefUtil::access(original).d_freeList_p)
534, d_blocksPerChunk(
bslmf::MovableRefUtil::access(original).d_blocksPerChunk)
537 lvalue.d_chunkList_p = 0;
538 lvalue.d_freeList_p = 0;
539 lvalue.d_blocksPerChunk = 1;
542template <
class VALUE,
class ALLOCATOR>
550template <
class VALUE,
class ALLOCATOR>
561 d_chunkList_p = lvalue.d_chunkList_p;
562 d_freeList_p = lvalue.d_freeList_p;
563 d_blocksPerChunk = lvalue.d_blocksPerChunk;
565 lvalue.d_chunkList_p = 0;
566 lvalue.d_freeList_p = 0;
567 lvalue.d_blocksPerChunk = 1;
570template <
class VALUE,
class ALLOCATOR>
578template <
class VALUE,
class ALLOCATOR>
585 VALUE *block =
reinterpret_cast<VALUE *
>(d_freeList_p);
586 d_freeList_p = d_freeList_p->d_next_p;
590template <
class VALUE,
class ALLOCATOR>
596 reinterpret_cast<Block *
>(address)->d_next_p = d_freeList_p;
597 d_freeList_p =
reinterpret_cast<Block *
>(address);
600template <
class VALUE,
class ALLOCATOR>
606 std::swap(d_blocksPerChunk, other.d_blocksPerChunk);
607 std::swap(d_freeList_p, other.d_freeList_p);
608 std::swap(d_chunkList_p, other.d_chunkList_p);
611template <
class VALUE,
class ALLOCATOR>
619template <
class VALUE,
class ALLOCATOR>
631 AllocTraits::propagate_on_container_copy_assignment::value ||
632 AllocTraits::propagate_on_container_move_assignment::value ||
633 AllocTraits::propagate_on_container_swap::value> Propagate;
636 using BloombergLP::bslma::AllocatorUtil;
637 AllocatorUtil::swap(&this->allocator(), &other.
allocator(), Propagate());
638 swap(d_blocksPerChunk, other.d_blocksPerChunk);
639 swap(d_freeList_p, other.d_freeList_p);
640 swap(d_chunkList_p, other.d_chunkList_p);
643template <
class VALUE,
class ALLOCATOR>
648 Block *begin = allocateChunk(numBlocks)->firstBlock();
649 Block *end = begin + numBlocks - 1;
652 for (Block *p = begin; p < end; ++p) {
655 end->d_next_p = d_freeList_p;
656 d_freeList_p = begin;
659template <
class VALUE,
class ALLOCATOR>
662 while (d_chunkList_p) {
663 Chunk *lastChunk = d_chunkList_p;
664 d_chunkList_p = d_chunkList_p->d_info.d_next_p;
665 deallocateChunk(lastChunk);
672template <
class VALUE,
class ALLOCATOR>
680template <
class VALUE,
class ALLOCATOR>
Definition bslmf_movableref.h:751
Definition bslstl_simplepool.h:292
void release()
Relinquish all memory currently allocated via this pool object.
Definition bslstl_simplepool.h:660
Types::AllocatorType AllocatorType
Definition bslstl_simplepool.h:341
void adopt(bslmf::MovableRef< SimplePool > pool)
Definition bslstl_simplepool.h:553
bool hasFreeBlocks() const
Definition bslstl_simplepool.h:682
const AllocatorType & allocator() const
Definition bslstl_simplepool.h:675
void quickSwapExchangeAllocators(SimplePool &other)
Definition bslstl_simplepool.h:621
VALUE ValueType
Alias for the parameterized type VALUE.
Definition bslstl_simplepool.h:337
void deallocate(void *address)
Definition bslstl_simplepool.h:592
AllocatorType & allocator()
Definition bslstl_simplepool.h:573
AllocatorTraits::size_type size_type
Definition bslstl_simplepool.h:347
~SimplePool()
Definition bslstl_simplepool.h:544
SimplePool(const ALLOCATOR &allocator)
Definition bslstl_simplepool.h:519
void quickSwapRetainAllocators(SimplePool &other)
Definition bslstl_simplepool.h:613
void reserve(size_type numBlocks)
Definition bslstl_simplepool.h:644
void swap(SimplePool &other)
Definition bslstl_simplepool.h:602
VALUE * allocate()
Definition bslstl_simplepool.h:580
SimplePool(bslmf::MovableRef< SimplePool > original)
Definition bslstl_simplepool.h:529
Types::AllocatorTraits AllocatorTraits
Definition bslstl_simplepool.h:345
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_ASSERT_SAFE(X)
Definition bsls_assert.h:1762
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:576
Definition bslstl_algorithm.h:82
void swap(TYPE &a, TYPE &b)
Definition bslma_allocatortraits.h:1061
Definition bslmf_integralconstant.h:244
static void deallocateBytes(const t_ALLOCATOR &allocator, typename AllocatorUtil_Traits< t_ALLOCATOR >::void_pointer p, std::size_t nbytes, std::size_t alignment=k_MAX_ALIGNMENT)
Definition bslma_allocatorutil.h:911
static AllocatorUtil_Traits< t_ALLOCATOR >::void_pointer allocateBytes(const t_ALLOCATOR &allocator, std::size_t nbytes, std::size_t alignment=k_MAX_ALIGNMENT)
Definition bslma_allocatorutil.h:871
static t_TYPE & access(t_TYPE &ref) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1032
Definition bsls_alignmentfromtype.h:376
AlignmentToType< VALUE >::Type Type
Definition bsls_alignmentfromtype.h:386
std::size_t UintPtr
Definition bsls_types.h:126
Definition bslstl_simplepool.h:266
AllocatorTraits::allocator_type AllocatorType
Definition bslstl_simplepool.h:275
bsl::allocator_traits< ALLOCATOR >::template rebind_traits< bsls::AlignmentUtil::MaxAlignedType > AllocatorTraits
Definition bslstl_simplepool.h:271