Giter Club home page Giter Club logo

object-pool's Introduction

object-pool

C++17 implementation of an object pool pattern

Description

This code is a fork & extension from the following code:

http://media.wiley.com/product_ancillary/50/11188580/DOWNLOAD/c25_code.zip

From the original source file:

--- cit ON

Provides an object pool that can be used with any class that provides a default constructor.

The object pool constructor creates a pool of objects, which it hands out to clients when requested via the acquireObject() method. acquireObject() returns an Object which is a std::shared_ptr with a custom deleter that automatically puts the object back into the object pool when the shared_ptr is destroyed and its reference reaches 0.

The constructor and destructor on each object in the pool will be called only once each for the lifetime of the program, not once per acquisition and release.

The primary use of an object pool is to avoid creating and deleting objects repeatedly. The object pool is most suited to applications that use large numbers of objects with expensive constructors for short periods of time, if a profiler tells you that allocating and deallocating these objects is a bottleneck.

--- cit OFF

It is also possible to create an object pool providing a non-default ctor for the objects that are registered and used at any new allocation when the pool is empty

Objects returned to the pool are reset by default.

See: https://en.wikipedia.org/wiki/Object_pool_pattern

See the unit tests for examples of use.

Requirements

cmake is used to compile the sources.

The default compiler used is clang++.

The cmake files compile with -std=c++20.

The unit tests are implemented in googletest: be sure you have installed googletest to compile.

Install

$ git clone https://github.com/massimo-marino/object-pool.git
$ cd object-pool
$ mkdir build
$ cd build
$ cmake ..
$ make

Run Unit Tests

Unit tests are implemented with googletest.

Install googletest to compile and run them.

$ cd src/unitTests
$ ./unitTests

Run Example [==Not Yet Implemented==]

$ cd ../example
$ ./object-pool-example

object-pool's People

Contributors

massimo-marino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.