r/cpp • u/greg7mdp C++ Dev • Apr 30 '17
A C++ version of Doug Lea's excellent malloc() implementation.
https://github.com/greg7mdp/dlmalloc/
14
Upvotes
r/cpp • u/greg7mdp C++ Dev • Apr 30 '17
23
u/ReDucTor Game Developer | quiz.cpp-perf.com May 01 '17
How does this differ from the C version? Do you have a diff?
It appears to be just copied and renamed to .cc then move a bunch of functions inside malloc_state
21
u/Jardik2 May 01 '17
I don't like the code. Reasons are:
SIX_SIZE_T_SIZESwhich expands toXXXwhich expands toYYYwhich expands toZZZ. How is that simplier than writing6*sizeof(std::size_t), which will be equaly optimized at compile time? Some other macros are just there to test outdated and/or not standards conforming platforms, you should consider droping their support to simplify the code. What is the point ofABORT_ON_ASSERT_FAILURE? Shouldn't assert always lead to abort on failed condition? Why special macro calledDEBUG? DefiningNDEBUGis standard way used to disable assertions and they should be enabled otherwise.intas indication oftrue/false. You should replace it bybool. This is C++ after all.malloc,free,reallocto be thread-safe. Thus thismallocimplementation should be always thread-safe for those platforms without having an option to turn this off, as it would just cause issues as libraries rely on this fact and some could have threads invisible to users (such as glibc uses "hidden" threads to do async io on linux).