How to allocate memory
Not to be a downer, but this is poor and outdated C programming style.<p>Don&#x27;t use sbrk(2) unless you&#x27;re completely reimplementing the standard library.<p>Don&#x27;t use alloca(3) unless you want weird headaches.  Just use dynamically-sized arrays, which have been present in C for nearly two decades.  They are block-scoped and easier to reason about.<p>None of the magic numbers are explained.  `(p-&gt;si_addr + (16LL&lt;&lt;22)) &amp; ~4095`, where do those come from?  I&#x27;m guessing 4095 is the page size less one, but DON&#x27;T hardcode that!<p>Don&#x27;t assign to lvalues in conditionals!  (e.g. `while(j&lt;31 &amp;&amp; !(h=free_table[j]))`)  It&#x27;s hard to read and bug-prone.<p>Don&#x27;t use `&amp;h[1]` to refer to the space after a structure.  I&#x27;m pretty sure that&#x27;s undefined behavior, and it often gives the wrong alignment for whatever you want to put after h.  Rather, add a final element to the structure of flexible array type (say `int data[]` if you&#x27;re storing ints after the structure).  That is guaranteed to have the semantics you&#x27;re looking for.<p>Here&#x27;s my advice:<p>1) Just use malloc(3).  It&#x27;s already fast and tuned to many allocation scenarios (including all four in this article!), and your application will continue to reap whatever performance improvements its maintainers make.  Use aligned_alloc(3) if you need pages.<p>2) When working in the embedded world, it&#x27;s often preferable to preallocate pools as large as your app will ever need for each kind of object you have collections of, and pin them to RAM (not necessarily for performance, but so you know you have the space).  If you do so, you can reference the objects by index rather than pointer.  It&#x27;s much faster and more space-efficient, especially on 64-bit architectures.<p>3) Don&#x27;t be afraid to realloc(3) to grow arrays.  It incurs no asymptotic penalty.<p>4) Pay attention to data layout, to make sure that commonly-accessed stuff is not interspersed with rarely-accessed stuff.  E.g. separate indexes from data where possible, if you tend to traverse the index rather than the data.<p>(Caveat: all my comments above apply to glibc.  YMWV on other systems.)