From 9fae7f92d6305b3c9a0791781f93c4487ed02384 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sat, 13 Oct 2018 11:32:46 +0300 Subject: [PATCH] mdbx-windows: use LocalAlloc/LocalFree instead of CRT's malloc/free. 2 of 17 for https://github.com/leo-yuriev/libmdbx/issues/43 Change-Id: Icb5289b55897d52ac00007f30b36bd84e5a0cbd1 --- src/osal.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/osal.h b/src/osal.h index 0f6e116b..3e2f6a68 100644 --- a/src/osal.h +++ b/src/osal.h @@ -84,6 +84,16 @@ typedef struct { HANDLE event; } mdbx_condmutex_t; typedef CRITICAL_SECTION mdbx_fastmutex_t; +static inline void *mdbx_malloc(size_t bytes) { + return LocalAlloc(LMEM_FIXED, bytes); +} +static inline void *mdbx_calloc(size_t nelem, size_t size) { + return LocalAlloc(LMEM_FIXED | LMEM_ZEROINIT, nelem * size); +} +static inline void *mdbx_realloc(void *ptr, size_t bytes) { + return LocalReAlloc(ptr, bytes, LMEM_MOVEABLE); +} +#define mdbx_free LocalFree #else #include #include @@ -103,12 +113,11 @@ typedef struct { pthread_cond_t cond; } mdbx_condmutex_t; typedef pthread_mutex_t mdbx_fastmutex_t; -#endif /* Platform */ - #define mdbx_malloc malloc #define mdbx_calloc calloc #define mdbx_realloc realloc #define mdbx_free free +#endif /* Platform */ /* *INDENT-OFF* */ /* clang-format off */