├── .github └── FUNDING.yml ├── README.md └── dlmalloc.cc /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: greg7mdp 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dlmalloc 2 | A C++ version of Doug Lea's excellent malloc() implementation. 3 | 4 | I have been having issues with the malloc() implementation on Windows, where the memory usage can grow unreasonably large with some patterns of successive reallocations. So I decided to investigate Doug Lea's [malloc implementation](http://g.oswego.edu/dl/html/malloc.html). It is very easy to use, a [single C file](ftp://g.oswego.edu/pub/misc/malloc.c) that you just compile and link along with your source code, and you are all set. 5 | 6 | Using Doug's malloc.c worked beautifully. For my use case, it was faster than Windows default malloc (I'm using Visual C++ 2015), and the memory usage was considerably reduced. 7 | 8 | I wanted to understand the code, as I would like to use its core logic to make a custom C++ allocator for my [sparse hash table](https://github.com/greg7mdp/sparsepp). However, I found the source code very difficult to follow. A lot of it is implemented with preprocessor macros, and is invisible to debuggers. Macros are of course necessary when coding in C for ultimate performance, but they sure obfuscate the code. 9 | 10 | Also, I'd like my C++ allocator to be header only, but shoving all these macro definitions into a header file would pollute the global name space, which is not acceptable. 11 | 12 | Therefore I decided to convert Doug's original malloc.c (v2.8.6) to C++, and this is what you find here. I have not modified what the code does, just how it is specified and organized (modulo any typo or bug I may have introduced of course). 13 | 14 | Interestingly, the C++ version is just as fast as the original C version! In my tests (Visual C++ 2015, Windows 10), the C++ version was even very slightly faster. 15 | 16 | While Linus may be opposed to C++, I still though that sharing this C++ implementation could be useful for people who, like me, would like to examine the inner workings of one of the best malloc implementation ever written. 17 | 18 | ### License 19 | 20 | Both the original source code from Doug Lea, and my changes are released to the public domain, as explained at http://creativecommons.org/publicdomain/zero/1.0/. 21 | --------------------------------------------------------------------------------