2 ms·
K&R includes an example memory allocator as well: https://stackoverflow.com/questions/13159564/explain-this-implementation-of-malloc-from-the-kr-book https://st
by pjc50 8y ago
K&R includes an example memory allocator as well: https://stackoverflow.com/questions/13159564/explain-this-implementation-of-malloc-from-the-kr-book 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.