|
@@ -1374,12 +1374,8 @@ mg_malloc_ex(size_t size,
|
|
(unsigned long)mstat->blockCount,
|
|
(unsigned long)mstat->blockCount,
|
|
file,
|
|
file,
|
|
line);
|
|
line);
|
|
-#if defined(_WIN32)
|
|
|
|
- OutputDebugStringA(mallocStr);
|
|
|
|
-#else
|
|
|
|
DEBUG_TRACE("%s", mallocStr);
|
|
DEBUG_TRACE("%s", mallocStr);
|
|
#endif
|
|
#endif
|
|
-#endif
|
|
|
|
|
|
|
|
return memory;
|
|
return memory;
|
|
}
|
|
}
|
|
@@ -1404,9 +1400,6 @@ mg_calloc_ex(size_t count,
|
|
static void
|
|
static void
|
|
mg_free_ex(void *memory, const char *file, unsigned line)
|
|
mg_free_ex(void *memory, const char *file, unsigned line)
|
|
{
|
|
{
|
|
- void *data = (void *)(((char *)memory) - 2 * sizeof(uintptr_t));
|
|
|
|
-
|
|
|
|
-
|
|
|
|
#if defined(MEMORY_DEBUGGING)
|
|
#if defined(MEMORY_DEBUGGING)
|
|
char mallocStr[256];
|
|
char mallocStr[256];
|
|
#else
|
|
#else
|
|
@@ -1415,11 +1408,13 @@ mg_free_ex(void *memory, const char *file, unsigned line)
|
|
#endif
|
|
#endif
|
|
|
|
|
|
if (memory) {
|
|
if (memory) {
|
|
|
|
+ void *data = (void *)(((char *)memory) - 2 * sizeof(uintptr_t));
|
|
uintptr_t size = ((uintptr_t *)data)[0];
|
|
uintptr_t size = ((uintptr_t *)data)[0];
|
|
struct mg_memory_stat *mstat =
|
|
struct mg_memory_stat *mstat =
|
|
(struct mg_memory_stat *)(((uintptr_t *)data)[1]);
|
|
(struct mg_memory_stat *)(((uintptr_t *)data)[1]);
|
|
mg_atomic_add(&mstat->totalMemUsed, -(int64_t)size);
|
|
mg_atomic_add(&mstat->totalMemUsed, -(int64_t)size);
|
|
mg_atomic_dec(&mstat->blockCount);
|
|
mg_atomic_dec(&mstat->blockCount);
|
|
|
|
+
|
|
#if defined(MEMORY_DEBUGGING)
|
|
#if defined(MEMORY_DEBUGGING)
|
|
sprintf(mallocStr,
|
|
sprintf(mallocStr,
|
|
"MEM: %p %5lu free %7lu %4lu --- %s:%u\n",
|
|
"MEM: %p %5lu free %7lu %4lu --- %s:%u\n",
|
|
@@ -1429,12 +1424,8 @@ mg_free_ex(void *memory, const char *file, unsigned line)
|
|
(unsigned long)mstat->blockCount,
|
|
(unsigned long)mstat->blockCount,
|
|
file,
|
|
file,
|
|
line);
|
|
line);
|
|
-#if defined(_WIN32)
|
|
|
|
- OutputDebugStringA(mallocStr);
|
|
|
|
-#else
|
|
|
|
DEBUG_TRACE("%s", mallocStr);
|
|
DEBUG_TRACE("%s", mallocStr);
|
|
#endif
|
|
#endif
|
|
-#endif
|
|
|
|
free(data);
|
|
free(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1478,12 +1469,8 @@ mg_realloc_ex(void *memory,
|
|
(unsigned long)mstat->blockCount,
|
|
(unsigned long)mstat->blockCount,
|
|
file,
|
|
file,
|
|
line);
|
|
line);
|
|
-#if defined(_WIN32)
|
|
|
|
- OutputDebugStringA(mallocStr);
|
|
|
|
-#else
|
|
|
|
DEBUG_TRACE("%s", mallocStr);
|
|
DEBUG_TRACE("%s", mallocStr);
|
|
#endif
|
|
#endif
|
|
-#endif
|
|
|
|
mg_atomic_add(&mstat->totalMemUsed, (int64_t)newsize);
|
|
mg_atomic_add(&mstat->totalMemUsed, (int64_t)newsize);
|
|
#if defined(MEMORY_DEBUGGING)
|
|
#if defined(MEMORY_DEBUGGING)
|
|
sprintf(mallocStr,
|
|
sprintf(mallocStr,
|
|
@@ -1494,22 +1481,14 @@ mg_realloc_ex(void *memory,
|
|
(unsigned long)mstat->blockCount,
|
|
(unsigned long)mstat->blockCount,
|
|
file,
|
|
file,
|
|
line);
|
|
line);
|
|
-#if defined(_WIN32)
|
|
|
|
- OutputDebugStringA(mallocStr);
|
|
|
|
-#else
|
|
|
|
DEBUG_TRACE("%s", mallocStr);
|
|
DEBUG_TRACE("%s", mallocStr);
|
|
#endif
|
|
#endif
|
|
-#endif
|
|
|
|
*(uintptr_t *)data = newsize;
|
|
*(uintptr_t *)data = newsize;
|
|
data = (void *)(((char *)data) + 2 * sizeof(uintptr_t));
|
|
data = (void *)(((char *)data) + 2 * sizeof(uintptr_t));
|
|
} else {
|
|
} else {
|
|
#if defined(MEMORY_DEBUGGING)
|
|
#if defined(MEMORY_DEBUGGING)
|
|
-#if defined(_WIN32)
|
|
|
|
- OutputDebugStringA("MEM: realloc failed\n");
|
|
|
|
-#else
|
|
|
|
DEBUG_TRACE("%s", "MEM: realloc failed\n");
|
|
DEBUG_TRACE("%s", "MEM: realloc failed\n");
|
|
#endif
|
|
#endif
|
|
-#endif
|
|
|
|
return _realloc;
|
|
return _realloc;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -1525,6 +1504,7 @@ mg_realloc_ex(void *memory,
|
|
return data;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
#define mg_malloc(a) mg_malloc_ex(a, NULL, __FILE__, __LINE__)
|
|
#define mg_malloc(a) mg_malloc_ex(a, NULL, __FILE__, __LINE__)
|
|
#define mg_calloc(a, b) mg_calloc_ex(a, b, NULL, __FILE__, __LINE__)
|
|
#define mg_calloc(a, b) mg_calloc_ex(a, b, NULL, __FILE__, __LINE__)
|
|
#define mg_realloc(a, b) mg_realloc_ex(a, b, NULL, __FILE__, __LINE__)
|
|
#define mg_realloc(a, b) mg_realloc_ex(a, b, NULL, __FILE__, __LINE__)
|
|
@@ -1534,8 +1514,10 @@ mg_realloc_ex(void *memory,
|
|
#define mg_calloc_ctx(a, b, c) mg_calloc_ex(a, b, c, __FILE__, __LINE__)
|
|
#define mg_calloc_ctx(a, b, c) mg_calloc_ex(a, b, c, __FILE__, __LINE__)
|
|
#define mg_realloc_ctx(a, b, c) mg_realloc_ex(a, b, c, __FILE__, __LINE__)
|
|
#define mg_realloc_ctx(a, b, c) mg_realloc_ex(a, b, c, __FILE__, __LINE__)
|
|
|
|
|
|
|
|
+
|
|
#else /* USE_SERVER_STATS */
|
|
#else /* USE_SERVER_STATS */
|
|
|
|
|
|
|
|
+
|
|
static __inline void *
|
|
static __inline void *
|
|
mg_malloc(size_t a)
|
|
mg_malloc(size_t a)
|
|
{
|
|
{
|