6

As an exercise I am writing a memory manager - that is, the code which implements malloc, realloc and free (or new and delete.) The RTL for my language, Delphi, allows the RTL's memory manager to be replaced easily. For those of you using C++, this is similar to, but lower-level than, overriding new and delete (it hooks into the RTL itself rather than being a language feature.) I'm looking for resources about high-quality approaches others have taken to the same problem.

I'm aware of a couple of memory management algorithms and implementations, including FastMM4 (quite complex), Doug Lea's allocator, Buddy, JeMalloc, TcMalloc, and Hoard. I am searching for information about the following:

  • Known, recommended algorithms: what other high-quality algorithms than the above have been published?

  • Are there specific algorithms tailored for highly threaded applications? That is, where there may be high thread contention at any locked points for allocation or freeing, and where memory may be allocated in one thread but deallocated in a different thread? Most algorithms - with the notable exceptions of Hoard, JeMalloc and TcMalloc - seem to be designed for single-threaded work, and the thread awareness is only thread safety in that there are locks or other synchronisation at appropriate points - no special design.

  • What do major vendors use? While Delphi and C++ Builder's is documented, I cannot find any information about the implementations used by MS VC++, .Net, or Objective C. (All documentation seems to be higher-level, such as NSAutoReleasePool for example. Linux seems to use Buddy.) These vendors do not seem to allow their RTL to be hooked into like Delphi does. I would be very interested to read about their implementations.

Community
  • 1
  • 1
David
  • 13,360
  • 7
  • 66
  • 130
  • 2
    Why the close vote? This question is not ambiguous, vague, incomplete, or rhetorical; nor is it broad in that it asks about algorithmic and known implementations for a specific, low-level problem. It should be clear. If you find it uncertain, please ask for clarification. – David Mar 19 '13 at 17:54
  • "this question will likely solicit debate, arguments, polling, or extended discussion" – Taryn East Mar 21 '13 at 11:43
  • When I commented, the only vote was for ambiguity. I'm afraid I don't see how it will solicit debate, arguments, polling or discussion, though. The questions seem fairly straightforward and answerable based by fact not opinion - I expect there to be statistics, papers / whitepapers, or at least experience, behind the first two parts - see the answer to the linked jemalloc for a good example, which includes a PDF whitepaper. The third is completely unambiguous, someone knows the answer or they don't. – David Mar 22 '13 at 11:33
  • @TarynEast: comment to tag your name, since you weren't tagged when I replied to you. – David Mar 22 '13 at 21:00
  • Do any of the moderators who closed have constructive comments on how to ask a less ambiguous or less likely to solicit debate question, please? (I am struggling to see why it fits either of those, yet several of you obviously think it does. Please help me understand why.) I'd appreciate helpful feedback since a vote with no comments - thanks @TarynEast for yours, and more would be great - is not useful. – David Mar 25 '13 at 13:20
  • 1
    Hi @David_M I think the problem is that you are asking for *more than one thing*. and people will have opinions on "which is the best thing". Sure you're asking for white-papers and good discussion.. but it is still discussion... and on S/O that often automatically leads to debate. S/O questions are these days aimed at specific one-answer questions. Your question, while interesting and valid... is not really an S/O type of question. Which is more aimed at "I'm having trouble implementing algorithm X, it fails at point Y with error message Z, can you tell me where I can look for a solution?" – Taryn East Apr 04 '13 at 03:51
  • Thanks @TarynEast . Would programmers.se be a better forum? If SO is narrowing to be easy question-answer then it seems less useful than it used to be - there's not so much value in having a wide pool of experts if the role here for answerers is helpdesk-like instead of being able to address wider, deeper questions. – David Apr 04 '13 at 10:47
  • 2
    Hi. That's a good question... unfortunately I don't know the answer to that one (plus programmers.se actually goes to a site in Swedish...) ;) Our experiences here differ. I've found S/O to be extremely helpful *because* it's helpdesk like question/answer - which means if I have a particular problem and google it - I know that S/O is a good place to find a working, specific answer - rather than a long discussion on wide-ranging tangential topics. YMMV :) – Taryn East Apr 08 '13 at 23:29

0 Answers0