Show HN: LibTTAK- Explicit lifetime-as-data for C systems

github.com

3 points by gg582 a day ago

LibTTAK is a C systems collection that moves lifetime management from control flow logic into the data model.

In traditional C, memory safety relies on the programmer correctly ordering `free()` calls. Even in C++ or Rust, while RAII and ownership rules automate this, the logic still lives in the control flow. LibTTAK encodes the lifetime directly into the allocation.

Key features:

Lifetime as data: Every allocation has an explicit expiry.

Access validation: `ttak_mem_access(ptr, tick)` enforces expiry checks at the data level.

Minimalistic cleanup: No GC, but automatically frees memory with an interval, which can be turned off. Also, the user can manually clean up targeted pointers.

Operational coupling: Simplifies staged shutdowns and subsystem boundaries by grouping allocations under a single lifetime.

The goal is to provide the safety of deterministic cleanup without the overhead of a garbage collector or the complexity of complex ownership tracking.

Docs: https://gg582.github.io/libttak

DenisDolya a day ago

Honestly, in many systems projects it is often simpler and safer to minimize or even avoid malloc entirely: rely more on stack, static buffers, or simple arenas. This usually leads to fewer bugs and more predictable behavior than building complex lifetime systems on top of the heap.

  • gg582 a day ago

    That is a valid point. When you are developing an application for an STM32, allocating memory on the heap is a bad idea. But if a programmer wants to make a high-performance back-end server in C, they should allocate unpredictable amounts of memory depending on a user's input(in many cases). This is not for Embedded/Hardware control; it aims for 'C Revival for High-level Development'. For a good example, many modern Rust applications do not statically fix memory areas; that is why Rust had to develop such a complex memory ownership system. In my personal opinion, with a bag of potato chips, you can do it better in C. Honestly, this does not have a proper memory tracker, so- yes. This does not have any advantages for now. However, I am planning to develop a memory lifetime tracker that can catch issues even before we run Valgrind or GDB. You can try to develop your own memory manager. This helped me to make my C-based web development framework safer through refactoring.

    :)