mempooled 0.3.1

Mempool implementation for dlang


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

mempooled

Latest version Dub downloads Actions Status codecov license

Fast efficient memory pools implementation supporting @nogc and betterC.

Note: Currently only fixedpool is implemented.

Docs

fixedpool

Implementation of "Fast Efficient Fixed-Size Memory Pool" as described in this article.

It can work as a pool for single templated type or generic pool with a fixed block size (so one can alloc various types with size less or equal to the block size - note however that space can be used inefficiently as one pool block can hold only one such item).

Minimal block size is 4B as data in blocks are used internally to form a linked list of the blocks.

Sample usage

import mempooled.fixed;

struct Foo {}

auto pool = fixedPool!(Foo, 10);
Foo* f = pool.alloc();

// some work

pool.dealloc(f);
f = null;

or with a generic pool:

import mempooled.fixed;

struct Foo
{
    int f;
    this(int f) { this.f = f; }
}
struct Bar {}

auto pool = fixedPool!(32, 100);
Foo* f = pool.alloc!Foo(42);
Bar* b = pool.alloc!Bar();
pool.dealloc(f);
pool.dealloc(b);

How to use the lib

Add it as a dependency to your dub project type or just copy the source code to your project.

Speed comparison

Tested with dub -b release --compiler=ldc2

For benchmark source code check benchmark subfolder.

Alloc
-----
fixedPool: 234 ms, 710 μs, and 5 hnsecs
GC:        831 ms, 890 μs, and 3 hnsecs
malloc:    448 ms, 686 μs, and 7 hnsecs

Dealloc
-------
fixedPool: 46 ms, 6 μs, and 1 hnsec
GC:        40 ms, 240 μs, and 1 hnsec
malloc:    75 ms, 354 μs, and 4 hnsecs
Authors:
  • Tomáš Chaloupka
Dependencies:
none
Versions:
0.4.0 2023-May-20
0.3.1 2022-Jan-30
0.3.0 2021-Oct-19
0.2.0 2021-Sep-25
0.1.2 2019-Dec-07
Show all 8 versions
Download Stats:
  • 16 downloads today

  • 64 downloads this week

  • 346 downloads this month

  • 13726 downloads total

Score:
3.2
Short URL:
mempooled.dub.pm