Skip to content

randommfs/HPool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple and blazingly fast pool allocator implementation

GitHub opened issues Status License Stars


HPool is a lightweight pool allocator supporting multiple types and dynamic extension.

Table of contents

Installation

The recommended way (for now) is using git submodules. If you want to integrate HPool into your project, add it as a submodule.

Building tests

To build tests, you need GTest available globally.

cmake -S. -Bbuild 
cmake --build build --target tests
build/tests

Usage

Preparation

Create pool object. If you want a single-type pool:

// Create a pool, that holds 32 ints.
HPool::HPool<int> pool(32);

If you want a multi-type pool:

// Create a combined pool, that can hold 32 objects of either int or string.
HPool::HPool<int, std::string> pool(32);

Use

Allocate memory:

auto ptr = pool.allocate();

For single-type pool, ptr has type HPool::Ptr<int>.
For multi-type pool, ptr has type HPool::Ptr<int, std::variant<int, std::string>>.

Free memory:

pool.free(ptr);

Get total count of elements:

uint32_t count = pool.size();

Get count of allocated elements:

uint32_t count = pool.allocated();

About

Simple pool implementation in C++

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •