3 comments

  • HexDecOctBin36 minutes ago
    The classic Doug Lee&#x27;s memory allocator[1] has explicit heaps by the name of mspaces. OP, were you aware of that; and if yes, what does your solution do better or different than dlmalloc&#x27;s mspaces?<p>[1] <a href="https:&#x2F;&#x2F;gee.cs.oswego.edu&#x2F;pub&#x2F;misc&#x2F;?C=N;O=D" rel="nofollow">https:&#x2F;&#x2F;gee.cs.oswego.edu&#x2F;pub&#x2F;misc&#x2F;?C=N;O=D</a>
  • ntoslinux21 minutes ago
    What is the reason for the weird `{ code };` blocks everywhere and is the below code machine generated?<p>```c ((PageSize) (chunk-&gt;pageSize - ((PageSize) ((PageSize) ((PageSize) (sizeof(Page) + (sizeof(struct _Block))) + (PageSize) ((sizeof(double)) - 1u)) &amp; ((PageSize) (~((PageSize) ((sizeof(double)) - 1u)))))) - ((PageSize) ((PageSize) ((PageSize) ((sizeof(FreeBlock) + sizeof(PageSize))) + (PageSize) (((((sizeof(double)) &gt; (4)) ? (sizeof(double)) : (4))) - ```
  • enduku2 days ago
    I wrote this because I wanted more explicit control over heaps when building different subsystems in C. Standard options like jemalloc and mimalloc are incredibly fast, but they act as black boxes. You can&#x27;t easily cap a parser&#x27;s memory at 256MB or wipe it all out in one go without writing a custom pool allocator.<p>Spaces takes a different approach. It uses 64KB-aligned slabs, and the metadata lookup is just a pointer mask (ptr &amp; ~0xFFFF).<p>The trade-off is that every free() incurs an L1 cache miss to read the slab header, and there is a 64KB virtual memory floor per slab. But in exchange, you get zero-external-metadata regions, instant teardown of massive structures like ASTs, and performance that surprisingly keeps up with jemalloc on cross-thread workloads (I included the mimalloc-bench scripts in the repo).<p>It&#x27;s Linux x86-64 only right now. I&#x27;m curious if systems folks think this chunk API is a pragmatic middle ground for memory management, or if the cache-miss penalty on free() makes the pointer-masking approach a dead end for general use.
    • throwaway20271 hour ago
      When dealing with memory in C defaulting to malloc or some opaque structure behind it is unless you just want to allocate and forget it for some one off program that frees memory on proc exit seems bad to me now. For any kind of sophisticated system or module you almost always want to write your own variety of slab, arena, pool, bump whatever it may be allocator.
    • bitbasher1 hour ago
      There&#x27;s a single commit in the whole repository. Was this AI generated?
      • sebazzz50 minutes ago
        You still have things like git squash etc.
        • bitbasher34 minutes ago
          That doesn&#x27;t make any sense. There&#x27;s 10,000+ lines of code. There shouldn&#x27;t be a single commit &quot;Initial commit&quot;. I&#x27;m fine with squashing some commits and creating a clean history, but this isn&#x27;t a clean history it&#x27;s obfuscated.
          • tosti3 minutes ago
            I also do this. Lots of weird commit messages because fuck that, I&#x27;m busy. Commits that are just there to put some stuff aside, things like that. I don&#x27;t owe it to anyone to show how messy my kitchen is.