Skip to content

Commit b82cf7b

Browse files
authored
Merge pull request #2260 from knewstimek/fix/windows-aligned-mimalloc
fix(windows): keep aligned allocations on mimalloc
2 parents c7488b0 + 2dba3cf commit b82cf7b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/foundation/compat_thread.c‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* compat_thread.c — Portable thread, mutex, and aligned allocation.
33
*
44
* POSIX: thin wrappers around pthreads and posix_memalign.
5-
* Windows: CreateThread, CRITICAL_SECTION, _aligned_malloc.
5+
* Windows: CreateThread, CRITICAL_SECTION, aligned allocation.
66
*/
77
#include "foundation/mem_events.h"
88
#include "foundation/constants.h"
@@ -279,12 +279,20 @@ void cbm_mutex_destroy(cbm_mutex_t *m) {
279279
#ifdef _WIN32
280280

281281
int cbm_aligned_alloc(void **ptr, size_t alignment, size_t size) {
282+
#if defined(CBM_MEM_GLOBAL_OVERRIDE) && CBM_MEM_GLOBAL_OVERRIDE
283+
*ptr = mi_malloc_aligned(size, alignment);
284+
#else
282285
*ptr = _aligned_malloc(size, alignment);
286+
#endif
283287
return *ptr ? 0 : -1;
284288
}
285289

286290
void cbm_aligned_free(void *ptr) {
291+
#if defined(CBM_MEM_GLOBAL_OVERRIDE) && CBM_MEM_GLOBAL_OVERRIDE
292+
mi_free(ptr);
293+
#else
287294
_aligned_free(ptr);
295+
#endif
288296
}
289297

290298
#else /* POSIX */

0 commit comments

Comments
 (0)