diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2019-02-08 17:22:52 -0500 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2019-03-12 15:21:32 -0400 |
commit | afe082642124dbda2367cb51c3d748873df9bf7b (patch) | |
tree | 0a795f2b3fc17e468c4b923357e6e803e85d818c /src/mongo/util/allocator.cpp | |
parent | c7e6cd6803e584a6951469e74af93ec3a7a47148 (diff) | |
download | mongo-afe082642124dbda2367cb51c3d748873df9bf7b.tar.gz |
SERVER-36243 Use sized deallocation.
Added mongoFree to be used when allocating memory with mongoMalloc.
It has an overload taking size utilizing tc_free_sized if built with tcmalloc.
Diffstat (limited to 'src/mongo/util/allocator.cpp')
-rw-r--r-- | src/mongo/util/allocator.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/mongo/util/allocator.cpp b/src/mongo/util/allocator.cpp index 358689a0655..d5beecdca87 100644 --- a/src/mongo/util/allocator.cpp +++ b/src/mongo/util/allocator.cpp @@ -33,10 +33,18 @@ #include "mongo/util/signal_handlers_synchronous.h" +#if defined(MONGO_USE_GPERFTOOLS_TCMALLOC) +#include <gperftools/tcmalloc.h> +#endif + namespace mongo { void* mongoMalloc(size_t size) { +#if defined(MONGO_USE_GPERFTOOLS_TCMALLOC) + void* x = tc_malloc(size); +#else void* x = std::malloc(size); +#endif if (x == NULL) { reportOutOfMemoryErrorAndExit(); } @@ -44,11 +52,31 @@ void* mongoMalloc(size_t size) { } void* mongoRealloc(void* ptr, size_t size) { +#if defined(MONGO_USE_GPERFTOOLS_TCMALLOC) + void* x = tc_realloc(ptr, size); +#else void* x = std::realloc(ptr, size); +#endif if (x == NULL) { reportOutOfMemoryErrorAndExit(); } return x; } +void mongoFree(void* ptr) { +#if defined(MONGO_USE_GPERFTOOLS_TCMALLOC) + tc_free(ptr); +#else + std::free(ptr); +#endif +} + +void mongoFree(void* ptr, size_t size) { +#if defined(MONGO_USE_GPERFTOOLS_TCMALLOC) + tc_free_sized(ptr, size); +#else + std::free(ptr); +#endif +} + } // namespace mongo |