mirror of
https://github.com/microsoft/mimalloc.git
synced 2025-05-06 15:29:31 +03:00
Merge branch 'dev3' into dev3-bin
This commit is contained in:
commit
4dc3537414
10 changed files with 25 additions and 23 deletions
|
@ -586,10 +586,13 @@ if(MI_BUILD_SHARED)
|
|||
install(EXPORT mimalloc DESTINATION ${mi_install_cmakedir})
|
||||
|
||||
if(WIN32)
|
||||
# On windows, the import library name for the dll would clash with the static mimalloc.lib
|
||||
# so we postfix the dll import library with `.dll.lib`.
|
||||
# On windows, the import library name for the dll would clash with the static mimalloc.lib library
|
||||
# so we postfix the dll import library with `.dll.lib` (and also the .pdb debug file)
|
||||
set_property(TARGET mimalloc PROPERTY ARCHIVE_OUTPUT_NAME "${mi_libname}.dll" )
|
||||
install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.lib" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
set_property(TARGET mimalloc PROPERTY PDB_NAME "${mi_libname}.dll")
|
||||
# don't try to install the pdb since it may not be generated depending on the configuration
|
||||
# install(FILES "$<TARGET_FILE_DIR:mimalloc>/${mi_libname}.dll.pdb" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
if(WIN32 AND MI_WIN_REDIRECT)
|
||||
# On windows, link and copy the mimalloc redirection dll too.
|
||||
|
|
Binary file not shown.
BIN
bin/minject.exe
BIN
bin/minject.exe
Binary file not shown.
Binary file not shown.
|
@ -1,15 +1,14 @@
|
|||
# Windows Override
|
||||
|
||||
<span id="override_on_windows">Dynamically overriding on mimalloc on Windows</span>
|
||||
is robust and has the particular advantage to be able to redirect all malloc/free calls
|
||||
that go through the (dynamic) C runtime allocator, including those from other DLL's or
|
||||
libraries. As it intercepts all allocation calls on a low level, it can be used reliably
|
||||
on large programs that include other 3rd party components.
|
||||
<span id="override_on_windows">We use a separate redirection DLL to override mimalloc on Windows</span>
|
||||
such that we redirect all malloc/free calls that go through the (dynamic) C runtime allocator,
|
||||
including those from other DLL's or libraries. As it intercepts all allocation calls on a low level,
|
||||
it can be used reliably on large programs that include other 3rd party components.
|
||||
There are four requirements to make the overriding work well:
|
||||
|
||||
1. Use the C-runtime library as a DLL (using the `/MD` or `/MDd` switch).
|
||||
|
||||
2. Link your program explicitly with the `mimalloc.lib` export library for
|
||||
2. Link your program explicitly with the `mimalloc.dll.lib` export library for
|
||||
the `mimalloc.dll` -- which contains all mimalloc functionality.
|
||||
To ensure the `mimalloc.dll` is actually loaded at run-time it is easiest
|
||||
to insert some call to the mimalloc API in the `main` function, like `mi_version()`
|
||||
|
|
|
@ -9,7 +9,7 @@ to check out a specific commit, version, or branch of mimalloc, or set further o
|
|||
You can install such custom port as:
|
||||
|
||||
```sh
|
||||
$ vcpkg install mimalloc[override] --recurse --overlay-ports=./contrib/vcpkg
|
||||
$ vcpkg install "mimalloc[override]" --recurse --overlay-ports=./contrib/vcpkg
|
||||
```
|
||||
|
||||
This will also show the correct sha512 hash if you use a custom version.
|
||||
|
|
|
@ -17,4 +17,5 @@ endif()
|
|||
if(TARGET mimalloc-static AND NOT TARGET mimalloc)
|
||||
add_library(mimalloc INTERFACE IMPORTED)
|
||||
set_target_properties(mimalloc PROPERTIES INTERFACE_LINK_LIBRARIES mimalloc-static)
|
||||
set_target_properties(mimalloc PROPERTIES INTERFACE_INCLUDE_DIRECTORIES mimalloc-static)
|
||||
endif()
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
"features": {
|
||||
"c": {
|
||||
"description": "Use C11 compilation (this can still override new/delete)"
|
||||
},
|
||||
},
|
||||
"override": {
|
||||
"description": "Override the standard malloc/free interface"
|
||||
},
|
||||
|
@ -31,6 +31,6 @@
|
|||
},
|
||||
"asm": {
|
||||
"description": "Generate assembly files"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
20
readme.md
20
readme.md
|
@ -165,8 +165,8 @@ mimalloc is used in various large scale low-latency services and programs, for e
|
|||
## Windows
|
||||
|
||||
Open `ide/vs2022/mimalloc.sln` in Visual Studio 2022 and build.
|
||||
The `mimalloc` project builds a static library (in `out/msvc-x64`), while the
|
||||
`mimalloc-override` project builds a DLL for overriding malloc
|
||||
The `mimalloc-lib` project builds a static library (in `out/msvc-x64`), while the
|
||||
`mimalloc-override-dll` project builds a DLL for overriding malloc
|
||||
in the entire program.
|
||||
|
||||
## Linux, macOS, BSD, etc.
|
||||
|
@ -475,16 +475,15 @@ the [shell](https://stackoverflow.com/questions/43941322/dyld-insert-libraries-i
|
|||
|
||||
# Windows Override
|
||||
|
||||
<span id="override_on_windows">Dynamically overriding on mimalloc on Windows</span>
|
||||
is robust and has the particular advantage to be able to redirect all malloc/free calls
|
||||
that go through the (dynamic) C runtime allocator, including those from other DLL's or
|
||||
libraries. As it intercepts all allocation calls on a low level, it can be used reliably
|
||||
on large programs that include other 3rd party components.
|
||||
<span id="override_on_windows">We use a separate redirection DLL to override mimalloc on Windows</span>
|
||||
such that we redirect all malloc/free calls that go through the (dynamic) C runtime allocator,
|
||||
including those from other DLL's or libraries. As it intercepts all allocation calls on a low level,
|
||||
it can be used reliably on large programs that include other 3rd party components.
|
||||
There are four requirements to make the overriding work well:
|
||||
|
||||
1. Use the C-runtime library as a DLL (using the `/MD` or `/MDd` switch).
|
||||
|
||||
2. Link your program explicitly with the `mimalloc.lib` export library for the `mimalloc.dll`.
|
||||
2. Link your program explicitly with the `mimalloc.dll.lib` export library for the `mimalloc.dll`.
|
||||
(which must be compiled with `-DMI_OVERRIDE=ON`, which is the default though).
|
||||
To ensure the `mimalloc.dll` is actually loaded at run-time it is easiest
|
||||
to insert some call to the mimalloc API in the `main` function, like `mi_version()`
|
||||
|
@ -501,9 +500,8 @@ There are four requirements to make the overriding work well:
|
|||
list of the final executable (so it can intercept all potential allocations).
|
||||
You can use `minject -l <exe>` to check this if needed.
|
||||
|
||||
For best performance on Windows with C++, it
|
||||
is also recommended to also override the `new`/`delete` operations (by including
|
||||
[`mimalloc-new-delete.h`](include/mimalloc-new-delete.h)
|
||||
For best performance on Windows with C++, it is also recommended to also override
|
||||
the `new`/`delete` operations (by including [`mimalloc-new-delete.h`](include/mimalloc-new-delete.h)
|
||||
a single(!) source file in your project).
|
||||
|
||||
The environment variable `MIMALLOC_DISABLE_REDIRECT=1` can be used to disable dynamic
|
||||
|
|
|
@ -201,7 +201,8 @@ static void* unix_mmap_prim(void* addr, size_t size, size_t try_alignment, int p
|
|||
void* p = NULL;
|
||||
#if defined(MAP_ALIGNED) // BSD
|
||||
if (addr == NULL && try_alignment > 1 && (try_alignment % _mi_os_page_size()) == 0) {
|
||||
size_t n = mi_bsr(try_alignment);
|
||||
size_t idx;
|
||||
size_t n = mi_bsr(try_alignment, &idx);
|
||||
if (((size_t)1 << n) == try_alignment && n >= 12 && n <= 30) { // alignment is a power of 2 and 4096 <= alignment <= 1GiB
|
||||
p = mmap(addr, size, protect_flags, flags | MAP_ALIGNED(n), fd, 0);
|
||||
if (p==MAP_FAILED || !_mi_is_aligned(p,try_alignment)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue