Hasty Briefsbeta

Show HN: I wrote a minimal memory allocator in C

6 hours ago
  • #C-programming
  • #memory-allocator
  • #system-programming
  • Custom implementation of malloc, calloc, realloc, and free in C.
  • Uses sbrk for small allocations and mmap for large allocations.
  • Includes optimizations like block splitting and coalescing to reduce fragmentation.
  • Not thread-safe; concurrent calls may cause undefined behavior.
  • Requires GCC, Make, and a POSIX-compliant system (Linux, macOS).
  • Build commands: `make`, `make tests`, `make bench`.
  • Example usage provided with `allocator.h` header and static library.
  • Project structure includes examples, tests, and benchmarks.
  • Limitations: No thread-safety, defragmentation, or compaction.
  • MIT License; contributions welcome.
  • Credits to Dan Luu's malloc tutorial and feedback from Joshua Zhou and Abdul Fatir.