microsoft / microsoft/mimalloc

Static override on Windows

Open
#268 5 comments 5 reactions 0 assignees View on GitHub
Dominant language
C
Stars
13.4k
Forks
1.2k
Avg merge
4d 45m
Merged PRs (30d)
13

Description

Hello!

Would it be possible to provide something like a static-override.c along with mimalloc? Other allocators have such implementation which allows to easily integrate mimalloc into a codebase & compile with the codebase's compiler and options.
See https://github.com/mjansson/rpmalloc/blob/develop/rpmalloc/malloc.c
Or https://github.com/microsoft/snmalloc/blob/master/src/override/malloc.cc

By applying the patch below, mimalloc can be linked as-a-lib along with said codebase. However when using optimization options or LTO/LTCG compilation, it'd be nice if the mimalloc source would be compiled into the codebase (considering /MT is being used, not /MD)

Many thanks!
Alex.

```
diff --git a/ide/vs2019/mimalloc.vcxproj b/ide/vs2019/mimalloc.vcxproj
index e18db0c..cdf2a0e 100644
--- a/ide/vs2019/mimalloc.vcxproj
+++ b/ide/vs2019/mimalloc.vcxproj
@@ -171,7 +171,7 @@
true
true
../../include
- %(PreprocessorDefinitions);NDEBUG
+ %(PreprocessorDefinitions);NDEBUG;MI_MALLOC_OVERRIDE
AssemblyAndSourceCode
$(IntDir)
false
@@ -180,6 +180,7 @@
CompileAsCpp
true
Default
+ MultiThreaded


true
diff --git a/src/alloc-override.c b/src/alloc-override.c
index a09153c..e9344ed 100644
--- a/src/alloc-override.c
+++ b/src/alloc-override.c
@@ -10,10 +10,10 @@ terms of the MIT license. A copy of the license can be found in the file
#endif

#if defined(MI_MALLOC_OVERRIDE) && defined(_WIN32) && !(defined(MI_SHARED_LIB) && defined(_DLL))
-#error "It is only possible to override "malloc" on Windows when building as a DLL (and linking the C runtime as a DLL)"
+//#error "It is only possible to override "malloc" on Windows when building as a DLL (and linking the C runtime as a DLL)"
#endif

-#if defined(MI_MALLOC_OVERRIDE) && !(defined(_WIN32)) // || (defined(__MACH__) && !defined(MI_INTERPOSE)))
+#if defined(MI_MALLOC_OVERRIDE) //&& !(defined(_WIN32)) // || (defined(__MACH__) && !defined(MI_INTERPOSE)))

// ------------------------------------------------------
// Override system malloc
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with src/alloc-override.c and the Windows project configuration in ide/vs2019/mimalloc.vcxproj, then compare the referenced rpmalloc and snmalloc override implementations. Check how the proposed definitions and runtime setting affect a static Windows build using /MT and optimization or LTO/LTCG. Done means a documented, buildable static override path for such codebases without relying on a DLL.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
build-system, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.