Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There doesn't seem to be that many good descriptions that go into the specifics about how dlmalloc works. The sources I have come across so far mention dlmalloc, but then only goes on to explain what malloc() and free() are, rather than describing dlmalloc.

The Wikipedia description, on the other hand, was a bit hard for me to understand.

Can anyone explain the workings of dlmalloc, how to implement it, and any additional sources that could help?

share|improve this question
up vote 3 down vote accepted

If you ever don't understand an implementation you should check the source, if available. Here's a fairly extensive explanation which was mentioned in the source.

Can anyone explain the workings of dlmalloc, how to implement it, and any additional sources that could help?

If you want to use dlmalloc then download the source. Creating your own version of malloc is going to be very difficult and will take you days reading to understand dlmalloc's source.

If you want to learn how dynamic memory works then I suggest you create a memory pool/allocator which will teach you everything you need to know. All you need to do is allocate a large buffer and create functions which allocate/free parts of that buffer.

share|improve this answer
I just have one quick question, though. Can dynamic memory ever "give memory back" to the system? I know that sbrk() is called whenever the heap needs to be extended when there are no suitable free blocks. However, I was wondering if the heap can be "shrinked" if there is a freed block at the very end of the heap, or if the highwater mark is there to stay until the whole process has been quit... – Dark Templar Oct 13 '11 at 18:40
@DarkTemplar Of course memory can be given back, but that doesn't mean that every implementation does so. sbrk() can be called to shrink the data segment, but as you said you'll need to make sure that no blocks are allocated at the end. – Pubby Oct 13 '11 at 18:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.