1.04.2012

µLIFO

Ya read right, I created a micro LIFO stack. Why micro you ask? Well, my current generic LIFO implementation bases on typeless data, needing to cast every access, wraping structures around memory areas and so on. That's totally fine in the context I'd use it in, but for my debugging system I'd have have the problem of a) having to create a bunch of variables and memories for each thread wanting to make use of it's debug/log stack though I know that it's all just an array and b) having decreased more handling code to write and some performance compared to an all-new array-based stack variant specialized to it's very specific task. So my goal was clear and simple: get rid of all these structures and formalities! So what I first realized was that in any case you'd need to know the stack's end and beginning. That's either a pointer like when having a memory area or a special data value like in a string. Pointers we had before, so the alternative is a special value. But what value? Using 0 like in strings is a bad idea cause storing null pointers would end the stack on insertion. So I decided to choose ~0 as start and end marks - one state less one is allowed to store in there (not a big deal if you ask me). The current interface is a bit like some sort of iterator but works awesome right now. The fact I only need to create a single array and a position variable is simply the most simple way how a stack can work. And it's even more memory effective than the old variant (addresses used directly, no wrapping structure around it). However, it is as specialized as it's useful and thus only designed for pointers and integers. I'm glad I'm taking the freedom to do something else in case of immediate toolkit necessity. I don't want to sit at the same problem all the time. It's makes your head marble and your mind drifiting.

I need to have more of those cool super-tiny and awesome macros. I really start to love macros right now, they make C so much more flexible and valuable if you know how other language reach their functionalities. You can still do all of it in C, though with some more explicit expressions.