Sha256: 16f8f7bf736654df0e9fe865eccc919cbeaabfccebe51fc7b704c5592bbc49ce

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

# Custom Memory Allocators

H3 supports replacing the memory management functions (`malloc`, `calloc`, `realloc`, `free`) used by the library at build time. This can be used to integrate H3 within a managed framework.

When using custom memory allocators, H3 prefixes the names of memory allocation functions with the string you specify. The application linking H3 must have the prefixed replacement functions defined.

When building H3, specify the `H3_ALLOC_PREFIX` option to your prefix of choice, as below:

```
cmake -DH3_ALLOC_PREFIX=my_prefix_ .
```

Then, in your application using H3, implement the following functions (replacing `my_prefix_` with the prefix you chose above):

```
void* my_prefix_malloc(size_t size);
void* my_prefix_calloc(size_t num, size_t size);
void* my_prefix_realloc(void* ptr, size_t size);
void my_prefix_free(void* ptr);
```

Link to H3 as you would have without the custom allocators. The custom allocators will be used for allocating heap memory in H3.

## Notes/Caveats

* There are a few algorithms like `kRing` that still use the call stack to recurse and could run out of memory that way.
* H3 does not currently use `realloc`.

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
h3-3.7.2 ext/h3/src/dev-docs/custom_alloc.md
h3-3.7.1 ext/h3/src/dev-docs/custom_alloc.md