diff --git a/dtool/src/dtoolbase/dtoolbase.h b/dtool/src/dtoolbase/dtoolbase.h index 66142427cc..d89caf2a92 100644 --- a/dtool/src/dtoolbase/dtoolbase.h +++ b/dtool/src/dtoolbase/dtoolbase.h @@ -387,6 +387,10 @@ typedef struct _object PyObject; // This specialized malloc implementation can perform the required alignment. #undef MEMORY_HOOK_DO_ALIGN +#elif defined(USE_MEMORY_MIMALLOC) +// This one does, too. +#undef MEMORY_HOOK_DO_ALIGN + #elif defined(USE_MEMORY_PTMALLOC2) // But not this one. For some reason it crashes when we try to build it with // alignment 16. So if we're using ptmalloc2, we need to enforce alignment @@ -438,7 +442,7 @@ typedef struct _object PyObject; #endif /* Determine our memory-allocation requirements. */ -#if defined(USE_MEMORY_PTMALLOC2) || defined(USE_MEMORY_DLMALLOC) || defined(DO_MEMORY_USAGE) || defined(MEMORY_HOOK_DO_ALIGN) +#if defined(USE_MEMORY_MIMALLOC) || defined(USE_MEMORY_PTMALLOC2) || defined(USE_MEMORY_DLMALLOC) || defined(DO_MEMORY_USAGE) || defined(MEMORY_HOOK_DO_ALIGN) /* In this case we have some custom memory management requirements. */ #else /* Otherwise, if we have no custom memory management needs at all, we diff --git a/dtool/src/dtoolbase/memoryHook.cxx b/dtool/src/dtoolbase/memoryHook.cxx index 24d5f11a11..7f5872d273 100644 --- a/dtool/src/dtoolbase/memoryHook.cxx +++ b/dtool/src/dtoolbase/memoryHook.cxx @@ -51,6 +51,18 @@ static_assert((MEMORY_HOOK_ALIGNMENT & (MEMORY_HOOK_ALIGNMENT - 1)) == 0, #if defined(CPPPARSER) +#elif defined(USE_MEMORY_MIMALLOC) + +// mimalloc is a modern memory manager by Microsoft that is very fast as well +// as thread-safe. + +#include "mimalloc.h" + +#define call_malloc mi_malloc +#define call_realloc mi_realloc +#define call_free mi_free +#undef MEMORY_HOOK_MALLOC_LOCK + #elif defined(USE_MEMORY_DLMALLOC) // Memory manager: DLMALLOC This is Doug Lea's memory manager. It is very diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index 42c35436f8..5d22f69026 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -103,6 +103,7 @@ PkgListSet(["PYTHON", "DIRECT", # Python support "PANDAPARTICLESYSTEM", # Built in particle system "CONTRIB", # Experimental "SSE2", "NEON", # Compiler features + "MIMALLOC", # Memory allocators ]) CheckPandaSourceTree() @@ -767,6 +768,7 @@ if (COMPILER == "MSVC"): if (PkgSkip("DIRECTCAM")==0): LibName("DIRECTCAM", "quartz.lib") if (PkgSkip("DIRECTCAM")==0): LibName("DIRECTCAM", "odbc32.lib") if (PkgSkip("DIRECTCAM")==0): LibName("DIRECTCAM", "odbccp32.lib") + if (PkgSkip("MIMALLOC")==0): LibName("MIMALLOC", GetThirdpartyDir() + "mimalloc/lib/mimalloc-static.lib") if (PkgSkip("OPENSSL")==0): if os.path.isfile(GetThirdpartyDir() + "openssl/lib/libpandassl.lib"): LibName("OPENSSL", GetThirdpartyDir() + "openssl/lib/libpandassl.lib") @@ -949,6 +951,8 @@ if (COMPILER == "MSVC"): LibName("BULLET", GetThirdpartyDir() + "bullet/lib/BulletSoftBody" + suffix) if (COMPILER=="GCC"): + PkgDisable("MIMALLOC") # no discernable benefit over glibc + if GetTarget() != "darwin": PkgDisable("CARBON") PkgDisable("COCOA") @@ -3766,7 +3770,7 @@ if GetTarget() == 'windows': # DIRECTORY: dtool/src/dtoolbase/ # -OPTS=['DIR:dtool/src/dtoolbase', 'BUILDING:DTOOL'] +OPTS=['DIR:dtool/src/dtoolbase', 'BUILDING:DTOOL', 'MIMALLOC'] TargetAdd('p3dtoolbase_composite1.obj', opts=OPTS, input='p3dtoolbase_composite1.cxx') TargetAdd('p3dtoolbase_composite2.obj', opts=OPTS, input='p3dtoolbase_composite2.cxx') TargetAdd('p3dtoolbase_lookup3.obj', opts=OPTS, input='lookup3.c') @@ -3797,7 +3801,7 @@ TargetAdd('libp3dtool.dll', input='p3dtoolbase_composite1.obj') TargetAdd('libp3dtool.dll', input='p3dtoolbase_composite2.obj') TargetAdd('libp3dtool.dll', input='p3dtoolbase_indent.obj') TargetAdd('libp3dtool.dll', input='p3dtoolbase_lookup3.obj') -TargetAdd('libp3dtool.dll', opts=['ADVAPI','WINSHELL','WINKERNEL']) +TargetAdd('libp3dtool.dll', opts=['ADVAPI','WINSHELL','WINKERNEL','MIMALLOC']) # # DIRECTORY: dtool/src/cppparser/