Giter Club home page Giter Club logo

dlmalloc's Introduction

dlmalloc

A C++ version of Doug Lea's excellent malloc() implementation.

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. It is very easy to use, a single C file that you just compile and link along with your source code, and you are all set.

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.

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. 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.

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.

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).

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.

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.

License

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/.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.