Hacker News new | ask | show | jobs
by pjc50 2805 days ago
K&R includes an example memory allocator as well: https://stackoverflow.com/questions/13159564/explain-this-im...

To me, the K&R one seems much less readable and also doesn't include the global malloc lock, since even the updated edition of K&R predates standardised threading.

I note it also does the "bp = (Header *)ap - 1;" trick, so if that's undefined behaviour then it's a good example of how hard it is to write C without relying on UB.