Path: blob/main/system/lib/mimalloc/include/mimalloc-override.h
6175 views
/* ----------------------------------------------------------------------------1Copyright (c) 2018-2020 Microsoft Research, Daan Leijen2This is free software; you can redistribute it and/or modify it under the3terms of the MIT license. A copy of the license can be found in the file4"LICENSE" at the root of this distribution.5-----------------------------------------------------------------------------*/6#pragma once7#ifndef MIMALLOC_OVERRIDE_H8#define MIMALLOC_OVERRIDE_H910/* ----------------------------------------------------------------------------11This header can be used to statically redirect malloc/free and new/delete12to the mimalloc variants. This can be useful if one can include this file on13each source file in a project (but be careful when using external code to14not accidentally mix pointers from different allocators).15-----------------------------------------------------------------------------*/1617#include <mimalloc.h>1819// Standard C allocation20#define malloc(n) mi_malloc(n)21#define calloc(n,c) mi_calloc(n,c)22#define realloc(p,n) mi_realloc(p,n)23#define free(p) mi_free(p)2425#define strdup(s) mi_strdup(s)26#define strndup(s,n) mi_strndup(s,n)27#define realpath(f,n) mi_realpath(f,n)2829// Microsoft extensions30#define _expand(p,n) mi_expand(p,n)31#define _msize(p) mi_usable_size(p)32#define _recalloc(p,n,c) mi_recalloc(p,n,c)3334#define _strdup(s) mi_strdup(s)35#define _strndup(s,n) mi_strndup(s,n)36#define _wcsdup(s) (wchar_t*)mi_wcsdup((const unsigned short*)(s))37#define _mbsdup(s) mi_mbsdup(s)38#define _dupenv_s(b,n,v) mi_dupenv_s(b,n,v)39#define _wdupenv_s(b,n,v) mi_wdupenv_s((unsigned short*)(b),n,(const unsigned short*)(v))4041// Various Posix and Unix variants42#define reallocf(p,n) mi_reallocf(p,n)43#define malloc_size(p) mi_usable_size(p)44#define malloc_usable_size(p) mi_usable_size(p)45#define malloc_good_size(sz) mi_malloc_good_size(sz)46#define cfree(p) mi_free(p)4748#define valloc(n) mi_valloc(n)49#define pvalloc(n) mi_pvalloc(n)50#define reallocarray(p,s,n) mi_reallocarray(p,s,n)51#define reallocarr(p,s,n) mi_reallocarr(p,s,n)52#define memalign(a,n) mi_memalign(a,n)53#define aligned_alloc(a,n) mi_aligned_alloc(a,n)54#define posix_memalign(p,a,n) mi_posix_memalign(p,a,n)55#define _posix_memalign(p,a,n) mi_posix_memalign(p,a,n)5657// Microsoft aligned variants58#define _aligned_malloc(n,a) mi_malloc_aligned(n,a)59#define _aligned_realloc(p,n,a) mi_realloc_aligned(p,n,a)60#define _aligned_recalloc(p,s,n,a) mi_aligned_recalloc(p,s,n,a)61#define _aligned_msize(p,a,o) mi_usable_size(p)62#define _aligned_free(p) mi_free(p)63#define _aligned_offset_malloc(n,a,o) mi_malloc_aligned_at(n,a,o)64#define _aligned_offset_realloc(p,n,a,o) mi_realloc_aligned_at(p,n,a,o)65#define _aligned_offset_recalloc(p,s,n,a,o) mi_recalloc_aligned_at(p,s,n,a,o)6667#endif // MIMALLOC_OVERRIDE_H686970