Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

C++ implementation of an object pool pattern

License

NotificationsYou must be signed in to change notification settings

massimo-marino/object-pool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 outto clients when requested via the acquireObject() method. acquireObject()returns an Object which is a std::shared_ptr with a custom deleter thatautomatically puts the object back into the object pool when the shared_ptris destroyed and its reference reaches 0.

The constructor and destructor on each object in the pool will be called onlyonce 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 objectsrepeatedly. The object pool is most suited to applications that use largenumbers of objects with expensive constructors for short periods of time, ifa profiler tells you that allocating and deallocating these objects is abottleneck.

--- cit OFF

It is also possible to create an object pool providing a non-default ctor forthe objects that are registered and used at any new allocation when the poolis 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 isclang++.

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

The unit tests are implemented ingoogletest: be sure you have installedgoogletest 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 withgoogletest.

Installgoogletest to compile and run them.

$cd src/unitTests$ ./unitTests

Run Example [==Not Yet Implemented==]

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

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp