summaryrefslogtreecommitdiff
path: root/deps/hdr_histogram/hdr_alloc.c
blob: d2bc611d93419c74da159fa5db55cfdad420bd6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
 * hdr_alloc.c
 * Written by Filipe Oliveira and released to the public domain,
 * as explained at http://creativecommons.org/publicdomain/zero/1.0/
 */

#include "hdr_alloc.h"
#include <stdlib.h>

hdrAllocFuncs hdrAllocFns = {
    .mallocFn = malloc,
    .callocFn = calloc,
    .reallocFn = realloc,
    .freeFn = free,
};

/* Override hdr' allocators with ones supplied by the user */
hdrAllocFuncs hdrSetAllocators(hdrAllocFuncs *override) {
    hdrAllocFuncs orig = hdrAllocFns;

    hdrAllocFns = *override;

    return orig;
}

/* Reset allocators to use build time defaults */
void hdrResetAllocators(void) {
    hdrAllocFns = (hdrAllocFuncs){
        .mallocFn = malloc,
        .callocFn = calloc,
        .reallocFn = realloc,
        .freeFn = free,
    };
}