Pool is C++17 memory pool template with different implementations(algorithms)

Object Pool

Description

Pool is C++17 object(memory) pool template with different implementations(algorithms)

The classic object pool pattern is a software creational design pattern that uses a set of initialized objects kept ready to use, rather than allocating and destroying them on demand. This Pool calls constructor of an object in the create method and destructor in the destroy method(memory for the object remains in the pool). This pool is more designed to optimize memory allocation for an object than to optimize construct/destruct of object. I use this pool as a memory manager(heap) for a specific type of objects.

Features

  • Header-only
  • Supported a different implementations(algorithms) see below
  • O(1) create/destroy of objects
  • Supported alignment of objects via use of aligned_storage
  • Some algorithms provide iterator support

Template Pool has the following parameters:

template <T, N, Align = alignof(T), Flags = 0, Impl = Pool_dlist>
  • T - The type of the elements.
  • N
    • The count of elemtnts in Static pool
    • The block size in Pool_xxx_block
    • Don't uses in Pool_xxx
  • Align - The alignment of items in the pool
  • Flags - The is an extended flags to tuning of implementation
  • Impl - This is a specific implementation(algorithm)
Algorithm:

Static:

Name Info
SPool_list Based on a singly-linked list
SPool_list_bitset Analogue of SPool_list, but we use bitset for the used nodes
SPool_dlist Based on a nested circular doubly-linked list

Dynamic:

Name Info
Pool_list Based on a singly-linked list
Pool_dlist Based on a nested circular doubly-linked list
Pool_list_block Analogue of Pool_list, but memory is allocated in blocks of N nodes
Pool_dlist_block Analogue of Pool_dlist, but memory is allocated in blocks of N nodes

More details see: pool.h

Usage

To start working, perform the following steps:

  1. Copy the pool.h into your project.
  2. Include pool.h
  3. Parameterize a template (see an examples)

Examples

#include <iostream>
#include "pool.h"

using namespace pool;

int main()
{
    const size_t N     = 10;
    const size_t Aling = alignof(int);
    Pool<int, N, Aling, 0, SPool_list> pool; //SPool_list don't support iterator

    auto i = pool.create(123);  // create obj
    std::cout << *i << "\n";    // use obj
    pool.destroy(i);            // destroy obj
}

We can use method for_each or iterators

#include <iostream>
#include "pool.h"

using namespace pool;

int main()
{
    const size_t N = 10;
    Pool<int, N> pool;

    for(size_t i = 0; i < N; i++)
        pool.create(i);

    pool.for_each([](int *i){ std::cout << *i << " ";});
    std::cout << "\n";

    //We can use for-range (If Impl support iterator)
    for(auto i :pool)
        std::cout << i << " ";
    std::cout << "\n";
}

For a more detailed description, see the API documentation.

Tests

cd tests
cmake . -B ./build
cd build
make

License

BSD-3-Clause

Similar Resources

Work Stealing Thread Pool

wstpool Work Stealing Thread Pool, Header Only, C++ Threads Consistent with the C++ async/future programming model. Drop-in replacement for 'async' fo

Oct 29, 2022

BabyCoin: mining pool

BabyCoin Pool Based on cryptonote-nodejs-pool cryptonote-nodejs-pool High performance Node.js (with native C addons) mining pool for CryptoNote based

May 15, 2022

MAN - Man is Thread Pool in C++17

Introduction MAN is a ThreadPool wrote in C++17. The name is chosen because, at least in France, it is said that men are not able to do several things

Mar 6, 2022

ThreadPool - A fastest, exception-safety and pure C++17 thread pool.

Warnings Since commit 468129863ec65c0b4ede02e8581bea682351a6d2, I move ThreadPool to C++17. (To use std::apply.) In addition, the rule of passing para

Dec 28, 2022

CTPL - Modern and efficient C++ Thread Pool Library

CTPL Modern and efficient C++ Thread Pool Library A thread pool is a programming pattern for parallel execution of jobs, http://en.wikipedia.org/wiki/

Dec 22, 2022

ThreadPool - A simple C++11 Thread Pool implementation

ThreadPool A simple C++11 Thread Pool implementation. Basic usage: // create thread pool with 4 worker threads ThreadPool pool(4); // enqueue and sto

Jan 7, 2023

Objectpool - Object pool implementation in C++11

Object pool allocator This is a C++11 implementation of an object pool allocator. For more information on object pool allocators and their purpose see

Nov 3, 2022

A modern thread pool implementation based on C++20

A modern thread pool implementation based on C++20

thread-pool A simple, functional thread pool implementation using pure C++20. Features Built entirely with C++20 Enqueue tasks with or without trackin

Dec 22, 2022

ParallelComputingPlayground - Shows different programming techniques for parallel computing on CPU and GPU

ParallelComputingPlayground Shows different programming techniques for parallel computing on CPU and GPU. Purpose The idea here is to compute a Mandel

May 16, 2020
Sqrt OS is a simulation of an OS scheduler and memory manager using different scheduling algorithms including Highest Priority First (non-preemptive), Shortest Remaining Time Next, and Round Robin
Sqrt OS is a simulation of an OS scheduler and memory manager using different scheduling algorithms including Highest Priority First (non-preemptive), Shortest Remaining Time Next, and Round Robin

A CPU scheduler determines an order for the execution of its scheduled processes; it decides which process will run according to a certain data structure that keeps track of the processes in the system and their status.

Sep 7, 2022
Thread pool - Thread pool using std::* primitives from C++17, with optional priority queue/greenthreading for POSIX.

thread_pool Thread pool using std::* primitives from C++11. Also includes a class for a priority thread pool. Requires concepts and C++17, including c

Dec 30, 2022
Thread-pool - Thread pool implementation using c++11 threads
Thread-pool - Thread pool implementation using c++11 threads

Table of Contents Introduction Build instructions Thread pool Queue Submit function Thread worker Usage example Use case#1 Use case#2 Use case#3 Futur

Dec 27, 2022
Thread-pool-cpp - High performance C++11 thread pool

thread-pool-cpp It is highly scalable and fast. It is header only. No external dependencies, only standard library needed. It implements both work-ste

Dec 17, 2022
A easy to use multithreading thread pool library for C. It is a handy stream like job scheduler with an automatic garbage collector. This is a multithreaded job scheduler for non I/O bound computation.

A easy to use multithreading thread pool library for C. It is a handy stream-like job scheduler with an automatic garbage collector for non I/O bound computation.

Jun 4, 2022
A C++17 thread pool for high-performance scientific computing.

We present a modern C++17-compatible thread pool implementation, built from scratch with high-performance scientific computing in mind. The thread pool is implemented as a single lightweight and self-contained class, and does not have any dependencies other than the C++17 standard library, thus allowing a great degree of portability

Jan 4, 2023
An easy to use C++ Thread Pool

mvThreadPool (This library is available under a free and permissive license) mvThreadPool is a simple to use header only C++ threadpool based on work

Dec 8, 2022
An ultra-simple thread pool implementation for running void() functions in multiple worker threads
An ultra-simple thread pool implementation for running void() functions in multiple worker threads

void_thread_pool.cpp © 2021 Dr Sebastien Sikora. [email protected] Updated 06/11/2021. What is it? void_thread_pool.cpp is an ultra-simple

Nov 19, 2021
EOSP ThreadPool is a header-only templated thread pool writtent in c++17.

EOSP Threadpool Description EOSP ThreadPool is a header-only templated thread pool writtent in c++17. It is designed to be easy to use while being abl

Apr 22, 2022
High Performance Linux C++ Network Programming Framework based on IO Multiplexing and Thread Pool

Kingpin is a C++ network programming framework based on TCP/IP + epoll + pthread, aims to implement a library for the high concurrent servers and clie

Oct 19, 2022