ORIGINAL
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | List of all members
original::objPoolAllocator< TYPE > Class Template Referencefinal

Object pool allocator for efficient fixed-size memory management. More...

#include <allocator.h>

Inheritance diagram for original::objPoolAllocator< TYPE >:
Inheritance graph
Collaboration diagram for original::objPoolAllocator< TYPE >:
Collaboration graph

Public Types

using propagate_on_container_move_assignment = std::true_type
 Allows propagation on move.
 
using propagate_on_container_swap = std::true_type
 Allows propagation on swap.
 
using propagate_on_container_merge = std::true_type
 Allows propagation on merge.
 
- Public Types inherited from original::allocatorBase< TYPE, objPoolAllocator >
using propagate_on_container_copy_assignment = std::false_type
 No propagation on copy.
 
using propagate_on_container_move_assignment = std::false_type
 No propagation on move.
 
using propagate_on_container_swap = std::false_type
 No propagation on swap.
 
using propagate_on_container_merge = std::false_type
 No propagation on merge.
 
using rebind_alloc = objPoolAllocator< O_TYPE >
 Rebinds allocator to different type.
 

Public Member Functions

 objPoolAllocator (u_integer size_class_count=8, u_integer count=4)
 Constructs a new object pool allocator.
 
 objPoolAllocator (const objPoolAllocator &)=delete
 Copy construction disabled.
 
objPoolAllocatoroperator= (const objPoolAllocator &)=delete
 Copy assignment disabled.
 
objPoolAllocatoroperator+= (objPoolAllocator &other)
 Merges another pool allocator into this one.
 
 objPoolAllocator (objPoolAllocator &&other) noexcept
 Move constructor.
 
objPoolAllocatoroperator= (objPoolAllocator &&other) noexcept
 Move assignment operator.
 
void swap (objPoolAllocator &other) noexcept
 Swaps the contents of two allocators.
 
TYPEallocate (u_integer size) override
 Allocates memory from the pool.
 
void deallocate (TYPE *ptr, u_integer size) override
 Returns memory to the pool.
 
 ~objPoolAllocator () override
 Destructor - releases all allocated memory.
 
- Public Member Functions inherited from original::allocatorBase< TYPE, objPoolAllocator >
constexpr allocatorBase ()
 Constructs a new allocatorBase instance.
 
void construct (O_TYPE *o_ptr, Args &&... args)
 Constructs an object in allocated memory.
 
virtual ~allocatorBase ()=0
 Virtual destructor.
 

Additional Inherited Members

- Static Public Member Functions inherited from original::allocatorBase< TYPE, objPoolAllocator >
static void destroy (O_TYPE *o_ptr)
 Destroys an object without deallocating.
 

Detailed Description

template<typename TYPE>
class original::objPoolAllocator< TYPE >

Object pool allocator for efficient fixed-size memory management.

Template Parameters
TYPEType of objects to allocate

Implements a memory allocator using an object pool pattern with these characteristics:

Memory Management Approach:

  1. The allocator maintains multiple free lists, one for each size class (power-of-two)
  2. When an allocation request comes in:
    • Finds the smallest size class that can satisfy the request
    • If no free chunks available, allocates a new block of chunks
    • For requests too large for the largest size class, uses global new
  3. When memory is deallocated:
    • Returns the chunk to its appropriate free list
    • Large allocations (outside pool) are freed immediately
Note
For large allocations, uses allocators::malloc/ allocators::free
See also
allocator For the default allocator implementation

Constructor & Destructor Documentation

◆ objPoolAllocator() [1/2]

template<typename TYPE >
original::objPoolAllocator< TYPE >::objPoolAllocator ( u_integer  size_class_count = 8,
u_integer  count = 4 
)
explicit

Constructs a new object pool allocator.

Parameters
size_class_countNumber of size classes to manage (default=8 → indices 0-7)
countInitial number of chunks per size class (default 4)

◆ objPoolAllocator() [2/2]

template<typename TYPE >
original::objPoolAllocator< TYPE >::objPoolAllocator ( objPoolAllocator< TYPE > &&  other)
noexcept

Move constructor.

Parameters
otherAllocator to move from
Note
Transfers ownership of all resources and leaves source in initialized state

Member Function Documentation

◆ allocate()

template<typename TYPE >
TYPE * original::objPoolAllocator< TYPE >::allocate ( u_integer  size)
overridevirtual

Allocates memory from the pool.

Parameters
sizeNumber of elements to allocate
Returns
Pointer to allocated memory
Exceptions
allocateErrorWhen memory allocation fails
Note
For large allocations, falls back to global operator new

Implements original::allocatorBase< TYPE, objPoolAllocator >.

◆ deallocate()

template<typename TYPE >
void original::objPoolAllocator< TYPE >::deallocate ( TYPE ptr,
u_integer  size 
)
overridevirtual

Returns memory to the pool.

Parameters
ptrPointer to memory to free
sizeNumber of elements originally allocated
Note
For large allocations, uses global operator delete

Implements original::allocatorBase< TYPE, objPoolAllocator >.

◆ operator+=()

Merges another pool allocator into this one.

Parameters
otherThe allocator to merge
Returns
Reference to this allocator

Merges:

  • Size class configurations (takes maximum)
  • Free lists (concatenates)
  • Allocated blocks (combines)
  • Allocator resources (since propagate_on_container_merge is true)

◆ operator=()

template<typename TYPE >
original::objPoolAllocator< TYPE > & original::objPoolAllocator< TYPE >::operator= ( objPoolAllocator< TYPE > &&  other)
noexcept

Move assignment operator.

Parameters
otherAllocator to move from
Returns
Reference to this allocator
Note
Releases current resources before taking ownership of new ones Leaves source in initialized state via poolInit()

◆ swap()

template<typename TYPE >
void original::objPoolAllocator< TYPE >::swap ( objPoolAllocator< TYPE > &  other)
noexcept

Swaps the contents of two allocators.

Parameters
otherAllocator to swap with

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