<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
      <title></title>
      <link>https://interlandi.io</link>
      <description></description>
      <generator>Zola</generator>
      <language>en</language>
      <atom:link href="https://interlandi.io/rss.xml" rel="self" type="application/rss+xml"/>
      <lastBuildDate>Sun, 11 Oct 2026 00:00:00 +0000</lastBuildDate>
      <item>
          <title>how to write a perfect arena allocator with zero issues</title>
          <pubDate>Sun, 11 Oct 2026 00:00:00 +0000</pubDate>
          <author>Unknown</author>
          <link>https://interlandi.io/blog/how-to-write-a-perfect-arena/</link>
          <guid>https://interlandi.io/blog/how-to-write-a-perfect-arena/</guid>
          <description xml:base="https://interlandi.io/blog/how-to-write-a-perfect-arena/">&lt;div id=&quot;top-anchor&quot;&gt;
&lt;p&gt;If you jumped from below. Jump back to &lt;a href=&quot;https://interlandi.io/blog/how-to-write-a-perfect-arena/#return-anchor&quot;&gt;where you came from&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;tl;dr:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_arena_alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;AK_Arena &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt; size_t&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt; unaligned_size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt; size_t&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt; align&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ||&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ||&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#   ifdef&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    align &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; align &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span&gt; AK_ASAN_BYTE_GRANULARITY &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;?&lt;/span&gt;&lt;span&gt; AK_ASAN_BYTE_GRANULARITY &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;:&lt;/span&gt;&lt;span&gt; align&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#   endif&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; //AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    ////////////////////////////////////////&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // ~~ Plan A: use the current slab ~~&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_likely&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#       ifdef&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; +=&lt;/span&gt;&lt;span&gt; AK_ASAN_PADDING_BYTES&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#       endif&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; // AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        uintptr_t&lt;/span&gt;&lt;span&gt; start_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_align_up&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uintptr_t&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; +&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; align&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        uintptr_t&lt;/span&gt;&lt;span&gt; end_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uintptr_t&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; +&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;cap&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_likely&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;start_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;+&lt;/span&gt;&lt;span&gt; unaligned_size_bytes &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span&gt; end_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_asan_unpoison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; unaligned_size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_memzero&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; unaligned_size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;+&lt;/span&gt;&lt;span&gt; unaligned_size_bytes &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;-&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#       ifdef&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; -=&lt;/span&gt;&lt;span&gt; AK_ASAN_PADDING_BYTES&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#       endif&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; // AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    //////////////////////////////////////////////////&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // ~~ Plan B: first-fit an existing free slab ~~&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_alloc_get_flags&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;host&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span&gt; AK_AllocatorFlag_NoRecycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        goto&lt;/span&gt;&lt;span&gt; plan_c&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_Slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;to_reuse &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    while&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;to_reuse &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        uintptr_t&lt;/span&gt;&lt;span&gt; start_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_align_up&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uintptr_t&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#           ifdef&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;                +&lt;/span&gt;&lt;span&gt; AK_ASAN_PADDING_BYTES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#           endif&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; // AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;            ,&lt;/span&gt;&lt;span&gt; align&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        uintptr_t&lt;/span&gt;&lt;span&gt; end_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uintptr_t&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; +&lt;/span&gt;&lt;span&gt; to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;cap&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;start_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;+&lt;/span&gt;&lt;span&gt; unaligned_size_bytes &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span&gt; end_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span&gt; to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;                ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_slab_unlink&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;+&lt;/span&gt;&lt;span&gt; unaligned_size_bytes &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;-&lt;/span&gt;&lt;span&gt; to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_asan_unpoison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; unaligned_size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_memzero&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; unaligned_size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        to_reuse &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; to_reuse&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    ////////////////////////////////////////&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // ~~ Plan C: allocate a new slab ~~&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;plan_c:&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    const size_t&lt;/span&gt;&lt;span&gt; default_slab_size &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_alloc_get_default_pre_allocation&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;host&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    const size_t&lt;/span&gt;&lt;span&gt; buf_size &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; unaligned_size_bytes &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;+&lt;/span&gt;&lt;span&gt; align &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; default_slab_size &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        unaligned_size_bytes &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;+&lt;/span&gt;&lt;span&gt; align &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        default_slab_size&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    const size_t&lt;/span&gt;&lt;span&gt; total_size &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;= sizeof&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;AK_Slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; +&lt;/span&gt;&lt;span&gt; buf_size&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_Slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;next_on_top &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;AK_Slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_alloc_nozero&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;host&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; total_size&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; _Alignof&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;AK_Slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;next_on_top &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_align_up&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uintptr_t&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; _Alignof&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;AK_Slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uintptr_t&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    ak_memzero&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; sizeof&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;AK_Slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;cap&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; buf_size&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    ak_asan_poison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;cap&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    uintptr_t&lt;/span&gt;&lt;span&gt; start_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_align_up&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uintptr_t&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#       ifdef&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;            +&lt;/span&gt;&lt;span&gt; AK_ASAN_PADDING_BYTES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#       endif&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; // AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        ,&lt;/span&gt;&lt;span&gt; align&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;              &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    ak_asan_unpoison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; unaligned_size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    ak_memzero&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; unaligned_size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; next_on_top&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;+&lt;/span&gt;&lt;span&gt; unaligned_size_bytes &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;-&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;start_addr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;note: This may not be what the allocator in the repository looks like by the time you read this.
If my code is wrong or could be better, email me or submit a PR (it would be greatly appreciated;
I would rather the code be right and I be wrong than I be right and the code be wrong).&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-s-an-allocator-anyway-what-s-an-arena&quot;&gt;What&#39;s an allocator, anyway? What&#39;s an arena?&lt;/h2&gt;
&lt;p&gt;An allocator (also known as a memory allocator) allocates memory by
dividing an existing chunk of bytes into smaller chunks in some way so that those chunks may be used by your program to store state.&lt;/p&gt;
&lt;p&gt;An arena allocator is a kind of allocator that functions effectively as a parallel call stack,
while being significantly safer for dynamically-sized things, and also decoupled from the control flow of your program.&lt;/p&gt;
&lt;p&gt;I would go into more detail, but &lt;a rel=&quot;external&quot; href=&quot;https://www.dgtlgrove.com/p/untangling-lifetimes-the-arena-allocator&quot;&gt;this article&lt;/a&gt; by Ryan Fleury explains
what this actually means, and why this is helpful with far more pedagogical clarity than I would be comfortable competing with.&lt;/p&gt;
&lt;h2 id=&quot;my-arena&quot;&gt;My Arena&lt;/h2&gt;
&lt;p&gt;Evidently, the main virtue of the arena allocator is that it is not substantially more complicated than assembling department store furniture.
So why is mine?&lt;/p&gt;
&lt;p&gt;The answer to that lies in the fact that, &lt;a rel=&quot;external&quot; href=&quot;https://github.com/Minterl/akimbo&quot;&gt;Akimbo&lt;/a&gt;, the thing this allocator was written for,
is a library. As such, I have multiple masters to serve, namely the hardware, the end user, and my sanity.&lt;/p&gt;
&lt;p&gt;By default, arenas serve two of those masters very well simultaneously.&lt;/p&gt;
&lt;h3 id=&quot;the-hardware&quot;&gt;The Hardware&lt;/h3&gt;
&lt;p&gt;If your point of reference is a global, process-wide, thread-safe, functionally dilettante nightmare, then arenas are incredibly fast. If your point of reference is&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;lea&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; rsp&lt;/span&gt;&lt;span&gt;, [&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt;rsp&lt;/span&gt;&lt;span&gt; - &lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt;rax&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;; alloca(/* whatever is in `rax` */);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;then they&#39;re still not that bad.&lt;/p&gt;
&lt;p&gt;The fast path cost of allocating memory from an arena is so negligible that the Amortized Dynamic Allocation Penalty™ shrinks to near-zero.&lt;/p&gt;
&lt;p&gt;This is not to mention that things allocated close to each other temporally are also allocated close to each other spatially. Why does that matter?&lt;/p&gt;
&lt;p&gt;Because actually reading and writing from the actual stick of silicon you call RAM is incredibly slow, the CPU generally accesses memory through a cache, a piece of
memory that is designed specifically to be bottlenecked by anything other than &quot;how fast do those electrons move.&quot;
The cache stores contiguous chunks of memory called cache lines. A component called the pre-fetcher
is capable of observing and predicting memory access patterns to speculatively load cache lines with the hope that they
will already be present by the time they&#39;re needed.&lt;/p&gt;
&lt;p&gt;Because of this, almost every application-grade processor made in the last 25 years will appear to be faster when accessing memory close to
whatever it just accessed.&lt;/p&gt;
&lt;p&gt;Now, what are stacks, and by extension arena allocators, condemned to do &lt;em&gt;infin a l&#39;etterno&lt;/em&gt;?&lt;/p&gt;
&lt;p&gt;Access memory close to whatever was just accessed.&lt;/p&gt;
&lt;h3 id=&quot;my-sanity&quot;&gt;My Sanity&lt;/h3&gt;
&lt;p&gt;They simplify the usage code commensurately with the amount they simplify the hardware&#39;s job.&lt;/p&gt;
&lt;p&gt;This point is best made by the aforementioned Ryan Fleury piece, but I&#39;ll do my best to summarize: instead of considering the lifetimes of
individual &quot;things,&quot; you group state by &quot;when is the first and last time this will ever need to exist,&quot; and let the invariants
of the arena do the rest of the work for you.&lt;/p&gt;
&lt;p&gt;This is objectively much simpler than the industry default &quot;untangle a pointer jungle&quot; model that tends to induce the existence of memory
management mechanisms like garbage collection and RAII.&lt;/p&gt;
&lt;h2 id=&quot;but-what-about-the-end-user&quot;&gt;But, what about the end user?&lt;/h2&gt;
&lt;p&gt;While the theory of the arena allocator may be one of the most beautiful concepts one encounters on the path to systems engineering priesthood,
it ignores the first question you have to answer when you write one: how much memory do I give it?&lt;/p&gt;
&lt;p&gt;If this is &lt;em&gt;your&lt;/em&gt; runtime and &lt;em&gt;your&lt;/em&gt; process under &lt;em&gt;your&lt;/em&gt; control, then it is perfectly reasonable to allocate 64 GB of virtual memory, and let demand paging
do what it was designed for.&lt;/p&gt;
&lt;p&gt;I, however, am writing a library where I do not know very much more about where my code will be running than it is a computer of some kind, probably. As such, I need
a means for the caller to inject their own allocation mechanisms.&lt;/p&gt;
&lt;h3 id=&quot;the-virtual-allocator&quot;&gt;The Virtual Allocator&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;note: It&#39;s not strictly necessary to understand the minutiae how the virtual allocator works to understand how the arena itself works,
but I thought it was interesting enough to write about. &lt;a href=&quot;https://interlandi.io/blog/how-to-write-a-perfect-arena/#arenas-again&quot;&gt;Skip this subsection&lt;/a&gt; if you don&#39;t care.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The specific flavor of Akimbo&#39;s virtual allocator is of enough substance to warrant an article on its own,
mostly to say that I stole it from Jonothan Blow&#39;s &lt;a rel=&quot;external&quot; href=&quot;https://jaiprogramming.com/&quot;&gt;Jai programming language&lt;/a&gt;, but I will go over it (not so) briefly.&lt;/p&gt;
&lt;p&gt;The most common solution to &quot;cyclic behavioral dependencies,&quot; i.e, where Part A of the program depends on the output of Part B, which needs something
from Part A (other than just passing something in) is a &lt;code&gt;vtable&lt;/code&gt;. The term &lt;code&gt;vtable&lt;/code&gt; is rather obfuscatory shorthand for &quot;struct of function pointers
and a state pointer&quot; -- something like this:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;typedef struct&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;TheVTable &lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    void&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;ctx&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; // our state ptr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;some_fn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;ctx&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt; int&lt;/span&gt;&lt;span&gt; some_arg&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    int&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;some_other_fn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;ctx&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt; int&lt;/span&gt;&lt;span&gt; some_other_arg&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;span&gt; TheVTable&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The issue: remember that pre-fetcher we talked about? It will frequently attempt to dereference things that look like memory addresses ahead of time, so that
when the code actually loads the value at that addresses, it&#39;s already sitting in the cache. This happens regardless of whether the data behind that
address is data in the traditional sense, or machine instructions.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;mov&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; rax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;qword&lt;/span&gt;&lt;span&gt; ptr [some_address] &lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;; the pre-fetcher can fetch this &amp;quot;data in the traditional sense&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;jmp&lt;/span&gt;&lt;span&gt; some_address &lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;; and these &amp;quot;machine instructions&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;However, consider this example:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;mov&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; rax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;qword&lt;/span&gt;&lt;span&gt; ptr [&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt;rdi&lt;/span&gt;&lt;span&gt;+&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;16&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;jmp&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; rax&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To execute this jump the CPU has to ...&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;figure out what &lt;code&gt;rdi + 16&lt;/code&gt; is,&lt;/li&gt;
&lt;li&gt;load the memory address behind &lt;code&gt;rdi + 16&lt;/code&gt; (explicitly into &lt;code&gt;rax&lt;/code&gt; for clarity),&lt;/li&gt;
&lt;li&gt;load the machine code behind the address in &lt;code&gt;rax&lt;/code&gt; into the cache,&lt;/li&gt;
&lt;li&gt;and set the program counter to the address in &lt;code&gt;rax&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The pre-fetcher cannot help you here. If it does not know where the machine code it needs to load is (because
the value is not in a register yet by step 1), it cannot load it. As such, the computer will commit a venial
cache miss.&lt;/p&gt;
&lt;p&gt;That is approximately what happens when you call a function behind a &lt;code&gt;vtable&lt;/code&gt; (I say approximately, because
you would actually set the arguments according to the calling convention, and use &lt;code&gt;call rax&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;The solution? Swap the layers of indirection. Instead of having the code be behind the table,
move the table behind the code:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;typedef uint8_t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_AllocatorMode&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;enum&lt;/span&gt;&lt;span&gt; AK_AllocatorMode &lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_AllocatorMode_Alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_AllocatorMode_Free&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_AllocatorMode_GetDefaultPreAllocation&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_AllocatorMode_GetFlags&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;typedef uint32_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_AllocatorFlags&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_AllocatorFlag_NoRecycle    &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; UINT32_C&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;0x&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_AllocatorFlag_AssumeZeroed &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; UINT32_C&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;0x&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; &amp;lt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;typedef union&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_AllocatorParams &lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    struct&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        size_t&lt;/span&gt;&lt;span&gt; size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        size_t&lt;/span&gt;&lt;span&gt; align&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;span&gt; alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    struct&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        size_t&lt;/span&gt;&lt;span&gt; size&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        size_t&lt;/span&gt;&lt;span&gt; align&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;span&gt; free&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // void get_default_pre_allocation&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // void get_flags&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;span&gt; AK_AllocatorParams&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;typedef union&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_AllocatorReturn &lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    struct&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;span&gt; alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // void free;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    struct&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        size_t&lt;/span&gt;&lt;span&gt; size_bytes&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;span&gt; get_default_pre_allocation&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    struct&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        AK_AllocatorFlags flags&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;span&gt; get_flags&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;span&gt; AK_AllocatorReturn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;typedef&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_AllocatorReturn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_AllocatorFunction&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;ctx&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; AK_AllocatorMode mode&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; AK_AllocatorParams params&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;/// To be passed by value, since it is not all that large, and doing so&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;/// eliminates dependent instruction loads.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;///&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;/// Don&amp;#39;t try to get clever and swap this out under the library&amp;#39;s feet between calls.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;/// That will almost certainly end poorly.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;typedef struct&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_Allocator &lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    /// Context passed to each allocator method.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    void&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;ctx&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_AllocatorFunction f&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;span&gt; AK_Allocator&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To understand this, let&#39;s look at a potential implementor:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_AllocatorReturn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;a_libc_based_allocator&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;ctx&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; AK_AllocatorMode &lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;mode_kind&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; AK_AllocatorParams &lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;params&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // this implementation in particular has some baggage related to alignment.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // don&amp;#39;t pay too much mind to it if it doens&amp;#39;t interest you.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;ctx&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    switch&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;mode_kind&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        case&lt;/span&gt;&lt;span&gt; AK_AllocatorMode_Alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            size_t&lt;/span&gt;&lt;span&gt; total_size &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;size_bytes&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; +&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;align&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; + sizeof&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;unaligned &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; malloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;total_size&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;!&lt;/span&gt;&lt;span&gt;unaligned&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;AK_AllocatorReturn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;){&lt;/span&gt;&lt;span&gt; .alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            size_t&lt;/span&gt;&lt;span&gt; to_ret_unaligned &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;size_t&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;unaligned &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;+ sizeof&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            size_t&lt;/span&gt;&lt;span&gt; aligned_int &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_align_up&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;to_ret_unaligned&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; params&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;align&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; **&lt;/span&gt;&lt;span&gt;header_ptr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;**&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)(&lt;/span&gt;&lt;span&gt;aligned_int &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;- sizeof&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;            *&lt;/span&gt;&lt;span&gt;header_ptr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; unaligned&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;AK_AllocatorReturn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;){&lt;/span&gt;&lt;span&gt; .alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;aligned_int &lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        case&lt;/span&gt;&lt;span&gt; AK_AllocatorMode_Free&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;: {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;original_ptr &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;= *&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;**&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)(&lt;/span&gt;&lt;span&gt;params&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;free&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; - sizeof&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            free&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;original_ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;AK_AllocatorReturn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;){&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        case&lt;/span&gt;&lt;span&gt; AK_AllocatorMode_GetDefaultPreAllocation&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;AK_AllocatorReturn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;){&lt;/span&gt;&lt;span&gt; .get_default_pre_allocation&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;size_bytes&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 1024&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 1024&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        case&lt;/span&gt;&lt;span&gt; AK_AllocatorMode_GetFlags&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;AK_AllocatorReturn&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;){&lt;/span&gt;&lt;span&gt; .get_flags&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;flags&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;};&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        default&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_unreachable&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Compilers like to compile dense switch statements into jump tables. Mechanically, this is very similar to a
&lt;code&gt;vtable&lt;/code&gt;. The assembly would look something like this:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;asm&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;cmp&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; rsi&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;ja&lt;/span&gt;&lt;span&gt; .the_default_case &lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;; if mode_kind &amp;gt; 3, jump to default case&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;lea&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; rax&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;qword&lt;/span&gt;&lt;span&gt; ptr .the_jump_table[&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt;rsi&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;8&lt;/span&gt;&lt;span&gt;] &lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;; load the jump target&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;jmp&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; rax&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;; imagine the code for each case is right here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.section .rodata&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;.align &lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;the_jump_table&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .quad .case_Alloc                  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .quad .case_Free                   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .quad .case_GetDefaultPreAllocation&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    .quad .case_GetFlags&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To execute this jump the CPU &lt;em&gt;still&lt;/em&gt; has to ...&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;figure out what &lt;code&gt;.the_jump_table[rsi*8]&lt;/code&gt; is,&lt;/li&gt;
&lt;li&gt;load the memory address behind &lt;code&gt;.the_jump_table[rsi*8]&lt;/code&gt; (explicitly into &lt;code&gt;rax&lt;/code&gt; for clarity),&lt;/li&gt;
&lt;li&gt;load the machine code behind the address in &lt;code&gt;rax&lt;/code&gt; into the cache,&lt;/li&gt;
&lt;li&gt;and set the program counter to the address in &lt;code&gt;rax&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;So why is this at all faster?&lt;/p&gt;
&lt;p&gt;In a &lt;code&gt;vtable&lt;/code&gt; each pointer points to a &lt;em&gt;different&lt;/em&gt; entire function. This means it will likely be very far away from the branch site
in the binary. However, In the case of the jump table, even if the jump table itself may cause the cache to miss (being that it is in
&lt;code&gt;.rodata&lt;/code&gt; rather than &lt;code&gt;.text&lt;/code&gt;), it is highly likely that the &lt;em&gt;target&lt;/em&gt; of the branch will always be roughly local to the branch site
and every other branch.&lt;/p&gt;
&lt;p&gt;There are other reasons too, like that that compilers will have an easier time optimizing
around them, since they can prove the control flow surrounding them.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;note: I framed the villain here as the &quot;pre-fetcher&quot; as a pedagogical falsehood since this isn&#39;t an article about CPU architecture,
and because I&#39;m not qualified to write one of those. The actual enemy here is the indirect branch predictor. If you want an interesting --
albeit dated -- paper on indirect branch prediction that explains this very well,
there&#39;s one &lt;a rel=&quot;external&quot; href=&quot;https://american.cs.ucdavis.edu/academic/readings/papers/driesen.pdf&quot;&gt;here&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If you can explain how wrong I am in 300 words or less, email me and I will quote and credit you here.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;arenas-again&quot;&gt;Arenas, Again&lt;/h3&gt;
&lt;p&gt;Almost 1000 words later and we still know nothing about how much memory to give the arena. What a terrible article.&lt;/p&gt;
&lt;p&gt;There are three common answer to this:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Pick a number.&lt;/li&gt;
&lt;li&gt;Pick a really big number and use virtual memory.&lt;/li&gt;
&lt;li&gt;Grow the arena (somehow).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Importantly, you cannot just &lt;code&gt;realloc&lt;/code&gt; the buffer. If there exists a single pointer to anything in your arena in your entire program state,
said pointer would be instantly invalidated.&lt;/p&gt;
&lt;p&gt;Akimbo&#39;s arena grows by adding a new &quot;slab&quot; (I am aware this term has prior art, but nobody cares) to a &quot;chain.&quot; Each slab looks like this:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;typedef struct&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_Slab &lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // these are called up/down rather than next/prev so it&amp;#39;s easier to visualize&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // them as a physical stack.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // not like a &amp;quot;the stack grows down&amp;quot; kind of stack, but a real-world stack of&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // something like paper.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // next and prev don&amp;#39;t mean all that much in this case regardless, since the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // &amp;quot;next&amp;quot; allocation can actually be &amp;quot;downwards&amp;quot; on this stack.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    struct&lt;/span&gt;&lt;span&gt; AK_Slab       &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    struct&lt;/span&gt;&lt;span&gt; AK_Slab       &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    size_t&lt;/span&gt;&lt;span&gt;                cap&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    uint8_t&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; _Alignas&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span&gt;  buf&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_check_bounds&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;cap&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;    // some writing may be coming soon about ^this bounds checking macro&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;span&gt; AK_Slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;note: That &lt;code&gt;[]&lt;/code&gt; syntax you see on the &lt;code&gt;buf&lt;/code&gt; member is C99 &lt;a rel=&quot;external&quot; href=&quot;https://en.wikipedia.org/wiki/Flexible_array_member&quot;&gt;flexible array member (FAM)&lt;/a&gt; syntax.
All it does is fix the issue where you would have had to manually pad a struct and/or invoke nasal demons to have some sort of
header/payload structure.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To summarize the snippet from the beginning ...&lt;/p&gt;
&lt;p&gt;&lt;em&gt;If I pasted this again, this article would be taller than me, but you can jump back to it &lt;a href=&quot;https://interlandi.io/blog/how-to-write-a-perfect-arena/#top-anchor&quot;&gt;here&lt;/a&gt;.
If you&#39;re reading this on a web page, you&#39;ll see a &quot;jump back&quot; link to get back here.&lt;/em&gt;&lt;/p&gt;
&lt;div id=&quot;return-anchor&quot; /&gt;
&lt;p&gt;... the allocator works approximately like this:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Plan A)&lt;/strong&gt; If there is enough space in the current &lt;code&gt;slab&lt;/code&gt;, take some memory out of it and give it back to the caller.&lt;br /&gt;
&lt;strong&gt;Plan B)&lt;/strong&gt; If there&#39;s not, we have a &quot;recycled list&quot; of slabs to choose from. Find a slab from there and give part of it back
to the caller.&lt;br /&gt;
&lt;strong&gt;Plan C)&lt;/strong&gt; If neither of those can happen, ask the host allocator for new memory. The amount of memory you ask for is either
some caller-set default value, or the minimum amount of memory needed to fit the requested allocation, aligned.&lt;/p&gt;
&lt;p&gt;The primary benefit of this approach is that depending on that caller-set default allocation size -- let&#39;s call it
&lt;code&gt;size&lt;/code&gt; -- the allocator may assume the behavior of different kinds of arenas. If &lt;code&gt;size&lt;/code&gt; is 0, then you always allocate
the exact size of each allocation. This is inefficient, and will use a lot more memory in the long term, but you end up with a
pseudo-garbage collector. If &lt;code&gt;size&lt;/code&gt; is something more reasonable, like 4 MB, you end up with an arena that takes up
a reasonable amount of address space, and is capable of requesting more. If &lt;code&gt;size&lt;/code&gt; is massive, like 64 GB, you end up
with a virtual memory-driven allocator that may take up a massive amount of address space, but is by far the fastest
version because, in practice, you will never see any branch other than &quot;Plan A.&quot;&lt;/p&gt;
&lt;p&gt;All of this is under a unified abstraction where the caller gets fine-grained control
over the memory consumption habits of the callee, without the ability or necessity for it to micromanage lifecycles.&lt;/p&gt;
&lt;h2 id=&quot;the-scoping-mechanism&quot;&gt;The Scoping Mechanism&lt;/h2&gt;
&lt;p&gt;The only other piece of this is &quot;what do I do when I&#39;m done with this memory?&quot; The answer is best understood with
a usage example:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;do_a_thing&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;AK_Arena &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_Scope scope &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_push_scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;some_memory &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_arena_alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 1024&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 32&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;some_memory &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        goto&lt;/span&gt;&lt;span&gt; out&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    use_the_memory&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;some_memory&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    uint8_t&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; *&lt;/span&gt;&lt;span&gt;some_more_memory &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_arena_alloc&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 102404837040&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 32&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;some_more_memory &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        goto&lt;/span&gt;&lt;span&gt; out&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    laksdfjlkasdjflkjl&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;some_more_memory&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;out:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;    ak_pop_scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; // &amp;quot;free&amp;quot; both at once!&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is relatively straightforward. When you&#39;re done with the function, you free all of the things you allocated.&lt;/p&gt;
&lt;p&gt;This is really simple to implement if you don&#39;t have a linked list of slabs to deal with. I do,
so the implementation looks like this and was about as pleasant to write as swallowing a live
pufferfish:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;AK_Scope&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_push_scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;AK_Arena &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;AK_Scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;){&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        .offset &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        .slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    };&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_pop_scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;AK_Arena &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; AK_Scope &lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_likely&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span&gt; scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; &amp;amp;&amp;amp;&lt;/span&gt;&lt;span&gt; scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;offset&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_asan_poison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; +&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;cap&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; -&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_AllocatorFlags flags &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_alloc_get_flags&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;host&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;flags &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt; AK_AllocatorFlag_NoRecycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;        ak_unreachable&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt;&amp;quot;TODO&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;ak_unlikely&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;        ak_arena_recycle_all&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        return&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    AK_Slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;to_recycle &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;current_offset&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; scope&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;.&lt;/span&gt;&lt;span&gt;offset&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;to_recycle &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        AK_Slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;prev_top_slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        // first, we break the chain below the final slab we want to recycle.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        // this forms a chain like this:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                  (nil)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //             [prev_top_slab]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    v&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                ..........&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    ^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    v&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //               [to_recycle]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                    v&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //                  (nil)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //            [the new top slab]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        //&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        // then, we recycle from the top slab all the way down to that point.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        // this one is confusing, so close your eyes and think about it.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        // break the chain&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span&gt; to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;        ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;prev_top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#       ifdef&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            AK_Slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;*&lt;/span&gt;&lt;span&gt;iter_slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;            while&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;iter_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;                ak_asan_poison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span&gt;iter_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;buf&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span&gt; iter_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;cap&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                iter_slab &lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;=&lt;/span&gt;&lt;span&gt; iter_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;            }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#       endif&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; // AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt;        // migrate the list&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;        if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;            ak_assert&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color: #F38BA8;&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;            (&lt;/span&gt;&lt;span&gt;arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)-&amp;gt;&lt;/span&gt;&lt;span&gt;up&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        to_recycle&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;down&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        arena&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;top_recycled_slab&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; =&lt;/span&gt;&lt;span&gt; prev_top_slab&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;addresssanitizer&quot;&gt;&lt;code&gt;AddressSanitizer&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;You certainly noticed &lt;code&gt;AK_FEATURE_ASAN&lt;/code&gt;, &lt;code&gt;ak_asan_poison&lt;/code&gt;, etc. seasoning the code. These interface with&lt;code&gt;AddressSanitizer&lt;/code&gt; (ASan).&lt;/p&gt;
&lt;h3 id=&quot;who-is-asan&quot;&gt;Who is ASan?&lt;/h3&gt;
&lt;p&gt;A grossly over-simplified explanation: ASan deems every single eight-byte region of your code either &quot;naughty&quot; or &quot;nice.&quot;
If you access (read to or write from) a naughty region, you crash, and get a letter from ASanta that read like this:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;==3543795==ERROR: AddressSanitizer: use-after-poison on address 0x7f7bd22fe870 at pc 0x55f161351120 bp 0x7fff5d8e9520 sp 0x7fff5d8e9510&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;READ of size 16 at 0x7f7bd22fe870 thread T0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #0 0x55f16135111f in main tools/mirv.c:4293&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #1 0x7f7bd2427780  (/usr/lib/libc.so.6+0x27780) (BuildId: 503200d7fda94a5dc6058d7e0694e5d1dcb2e372)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #2 0x7f7bd24278b8 in __libc_start_main (/usr/lib/libc.so.6+0x278b8) (BuildId: 503200d7fda94a5dc6058d7e0694e5d1dcb2e372)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    #3 0x55f161316334 in _start (/home/mike/repo/libgrad/out/tools/mirv.out+0x17334) (BuildId: 6eb12e75e7167875943f7aa08ec0a14320dbcd51)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If you read from a nice region, nothing happens.&lt;/p&gt;
&lt;p&gt;By default, if you enable &lt;code&gt;ASan&lt;/code&gt; -- which you can do by compiling your code with &lt;code&gt;-fsanitize=address&lt;/code&gt; -- every region that you probably
shouldn&#39;t be looking at (like stuff that isn&#39;t a heap/stack/data region allocation), is already naughty. It also pads
each valid region with a proportionate amount of poisoned memory to catch over/underflows.&lt;/p&gt;
&lt;p&gt;However, &lt;code&gt;ASan&lt;/code&gt; knows absolutely nothing about your own custom allocators.
If you want safety for those, you can ...&lt;/p&gt;
&lt;h3 id=&quot;instrument-the-code&quot;&gt;Instrument the code!&lt;/h3&gt;
&lt;p&gt;It all starts with a macro soup ...&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_ASAN_PADDING_BYTES&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 16&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#define&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_ASAN_BYTE_GRANULARITY&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt; 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#if&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: #F5C2E7;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;defined&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;__has_feature&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; &amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; __has_feature&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;address_sanitizer&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; ||&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt; defined&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;__SANITIZE_ADDRESS__&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;))&lt;/span&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt; &amp;amp;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: #F5C2E7;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #94E2D5;&quot;&gt;    !&lt;/span&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;defined&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;AK_NO_ASAN&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #F5C2E7;&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#   include&lt;/span&gt;&lt;span style=&quot;color: #A6E3A1;&quot;&gt; &amp;lt;sanitizer/asan_interface.h&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#   define&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; AK_FEATURE_ASAN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#   define&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_asan_poison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt;   ASAN_POISON_MEMORY_REGION&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;), (&lt;/span&gt;&lt;span&gt;len&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#   define&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_asan_unpoison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ASAN_UNPOISON_MEMORY_REGION&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;((&lt;/span&gt;&lt;span&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;), (&lt;/span&gt;&lt;span&gt;len&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#else&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#   define&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_asan_poison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)   ((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)(&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#   define&lt;/span&gt;&lt;span style=&quot;color: #89B4FA;font-style: italic;&quot;&gt; ak_asan_unpoison&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt;ptr&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: #EBA0AC;font-style: italic;&quot;&gt; len&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;) ((&lt;/span&gt;&lt;span style=&quot;color: #CBA6F7;&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;)(&lt;/span&gt;&lt;span style=&quot;color: #FAB387;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #9399B2;&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F9E2AF;&quot;&gt;#endif&lt;/span&gt;&lt;span style=&quot;color: #9399B2;font-style: italic;&quot;&gt; // defined(__has_feature) &amp;amp;&amp;amp; __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;ASAN_POISON_MEMORY_REGION&lt;/code&gt; marks a range of addresses as naughty, and &lt;code&gt;ASAN_UNPOISON_MEMORY_REGION&lt;/code&gt; marks them as nice.
These operations are idempotent.&lt;/p&gt;
&lt;p&gt;Because of a certain &lt;a rel=&quot;external&quot; href=&quot;https://github.com/google/sanitizers/wiki/addresssanitizeralgorithm&quot;&gt;shadow memory&lt;/a&gt; mechanism, you
should only ever mark regions of at least eight aligned bytes as naughty (or multiples thereof). This is
&lt;code&gt;AK_ASAN_BYTE_GRANULARITY&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;AK_ASAN_PADDING_BYTES&lt;/code&gt; is a constant because it&#39;s simple, and is enough to catch most over/underflows.
&lt;code&gt;AK_Slab&lt;/code&gt;s are padded internally and externally like this:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #CDD6F4; background-color: #1E1E2E;&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    slab starts here -&amp;gt; |                       inside the slab                                                  | &amp;lt;- slab ends here&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;*************************--------**********************-------------------**********************-----------------*************************&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[default poisoned memory][header][user-poisoned-memory][actual valid data][user-poisoned memory][more valid data][default poisoned memory]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This is trivial to implement in an arena allocator. If all of the internal memory is poisoned by default, all you have to do
is prepend a few bytes to each allocation, and you will never have any bugs ever again.&lt;/p&gt;
&lt;h2 id=&quot;aside-zig&quot;&gt;Aside: Zig&lt;/h2&gt;
&lt;p&gt;Zig the programming language is good. Zig the programming language and standard library is not as good.&lt;/p&gt;
&lt;p&gt;This may be an inherent property of standard libraries in general, but Zig&#39;s arena allocator is particularly guilty.&lt;/p&gt;
&lt;p&gt;I decided a couple weeks ago to shout into the void about this on &lt;a rel=&quot;external&quot; href=&quot;https://x.com/1nterlandi/status/2101386335185494502&quot;&gt;the internet&lt;/a&gt;. I believe I said it best
when I said ...&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;it is thread-safe (which makes very little sense for an arena, but has to be that way because it gets type erased),
gives you no fine-grained control over lifetimes (because it can&#39;t since &lt;em&gt;technically&lt;/em&gt; multiple threads can use it at once),
if you use it idiomatically, you still have to write free calls everywhere (which mitigates much of the benefit), and essentially ignores resizes.
it is an afterthought in the purest sense.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;In retrospect, I may have been upset over electricity in a computer.&lt;/p&gt;
&lt;p&gt;:w,&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Mike&lt;/em&gt;&lt;/p&gt;
&lt;style&gt;
    /* for jump and return anchors */
    #top-anchor {
        display: none;
    }
    #top-anchor:target {
        display: block;
    }
&lt;/style&gt;
</description>
      </item>
    </channel>
</rss>
