achierius 2 hours ago

Looks nice! Though I have to say, you should probably avoid sbreak even for small allocations -- obviously it's slow, but even beyond that you have to deal with the fact that it's essentially a global singleton and introduces a lot of subtle failure cases you might not think of + which you can't really solve anyways. It's better to mmap out some chunk of memory and sub-allocate it out yourself.

  • macintux an hour ago

    Can you supply an example of a failure case that can’t be solved (or is at least challenging to solve)?

    • sweetjuly 18 minutes ago

      sbrk grows linearly, and if anything is mapped in the way it fails. mmap can map anywhere there's space as it is not restricted to linear mappings. So, you'd better hope a mapping doesn't randomly land there and run you out of space.

      It's not a failure but relatedly as sbrk is linear, you also don't really have a reasonable way to deal with fragmentation. For example, suppose you allocate 1000 page sized objects and then free all but the last one. With an mmap based heap, you can free all 999 other pages back to the OS whereas with sbrk you're stuck with those 999 pages you don't need for the lifetime of that 1000th object (better hope it's not long lived!).

      Really, sbrk only exists for legacy reasons.

checker659 an hour ago

That project structure is reminding me of claude.

  • keyle 34 minutes ago

    So does half the readme

quibono 2 hours ago

I hate that very often my first reaction to Show HN posts like this is to cynically look for signs of blatant AI code use.

I don't think that's the case here though.