|
| 1 | +/* ---------------------------------------------------------------------------- |
| 2 | +Copyright (c) 2018-2020 Microsoft Research, Daan Leijen |
| 3 | +This is free software; you can redistribute it and/or modify it under the |
| 4 | +terms of the MIT license. A copy of the license can be found in the file |
| 5 | +"LICENSE" at the root of this distribution. |
| 6 | +-----------------------------------------------------------------------------*/ |
| 7 | +#pragma once |
| 8 | +#ifndef MIMALLOC_OVERRIDE_H |
| 9 | +#define MIMALLOC_OVERRIDE_H |
| 10 | + |
| 11 | +/* ---------------------------------------------------------------------------- |
| 12 | +This header can be used to statically redirect malloc/free and new/delete |
| 13 | +to the mimalloc variants. This can be useful if one can include this file on |
| 14 | +each source file in a project (but be careful when using external code to |
| 15 | +not accidentally mix pointers from different allocators). |
| 16 | +-----------------------------------------------------------------------------*/ |
| 17 | + |
| 18 | +#include "mimalloc.h" |
| 19 | + |
| 20 | +// Standard C allocation |
| 21 | +#define malloc(n) mi_malloc(n) |
| 22 | +#define calloc(c,n) mi_calloc(c,n) |
| 23 | +#define realloc(p,n) mi_realloc(p,n) |
| 24 | +#define free(p) mi_free(p) |
| 25 | + |
| 26 | +#define strdup(s) mi_strdup(s) |
| 27 | +#define strndup(s,n) mi_strndup(s,n) |
| 28 | +#define realpath(f,n) mi_realpath(f,n) |
| 29 | + |
| 30 | +// Microsoft extensions |
| 31 | +#define _expand(p,n) mi_expand(p,n) |
| 32 | +#define _msize(p) mi_usable_size(p) |
| 33 | +#define _recalloc(p,c,n) mi_recalloc(p,c,n) |
| 34 | + |
| 35 | +#define _strdup(s) mi_strdup(s) |
| 36 | +#define _strndup(s,n) mi_strndup(s,n) |
| 37 | +#define _wcsdup(s) mi_wcsdup(s) |
| 38 | +#define _mbsdup(s) mi_mbsdup(s) |
| 39 | +#define _dupenv_s(buf,n,nm) mi_dupenv_s(buf,n,nm) |
| 40 | +#define _wdupenv_s(buf,n,nm) mi_wdupenv_s(buf,n,nm) |
| 41 | + |
| 42 | +// Various Posix and Unix variants |
| 43 | +#define reallocf(p,n) mi_reallocf(p,n) |
| 44 | +#define malloc_size(p) mi_usable_size(p) |
| 45 | +#define malloc_usable_size(p) mi_usable_size(p) |
| 46 | +#define malloc_good_size(n) mi_malloc_good_size(n) |
| 47 | +#define cfree(p) mi_free(p) |
| 48 | + |
| 49 | +#define valloc(n) mi_valloc(n) |
| 50 | +#define pvalloc(n) mi_pvalloc(n) |
| 51 | +#define reallocarray(p,c,n) mi_reallocarray(p,c,n) |
| 52 | +#define reallocarr(ptrp,c,n) mi_reallocarr(ptrp,c,n) |
| 53 | +#define memalign(a,n) mi_memalign(a,n) |
| 54 | +#define aligned_alloc(a,n) mi_aligned_alloc(a,n) |
| 55 | +#define posix_memalign(p,a,n) mi_posix_memalign(p,a,n) |
| 56 | +#define _posix_memalign(p,a,n) mi_posix_memalign(p,a,n) |
| 57 | + |
| 58 | +// Microsoft aligned variants |
| 59 | +#define _aligned_malloc(n,a) mi_malloc_aligned(n,a) |
| 60 | +#define _aligned_realloc(p,n,a) mi_realloc_aligned(p,n,a) |
| 61 | +#define _aligned_recalloc(p,c,n,a) mi_aligned_recalloc(p,c,n,a) |
| 62 | +#define _aligned_msize(p,a,o) mi_usable_size(p) |
| 63 | +#define _aligned_free(p) mi_free(p) |
| 64 | +#define _aligned_offset_malloc(n,a,o) mi_malloc_aligned_at(n,a,o) |
| 65 | +#define _aligned_offset_realloc(p,n,a,o) mi_realloc_aligned_at(p,n,a,o) |
| 66 | +#define _aligned_offset_recalloc(p,c,n,a,o) mi_recalloc_aligned_at(p,c,n,a,o) |
| 67 | + |
| 68 | +#endif // MIMALLOC_OVERRIDE_H |
0 commit comments