In-place array uniq in C

I’ve been developing Insight even though the uni project has come to an end, because it’s fun! I also want to make it more stable and eventually release it under an open-source licence of some kind. There will be an update coming soon, I promise! I now have Internet, so I can write up some things… Anyway, one of the interesting things I wanted to do for Insight was an in-place form of uniq for an array, ideally without any additional memory allocation. It seems that this is something nobody else has done yet! So I set about doing it myself… For those of you who are unfamiliar with the Linux/UNIX command uniq, it takes a sorted list and removes any duplicates. This is almost exactly what I’m trying to do, with one caveat: I need to keep the “discarded” duplicates. What happens is that I have an array containing a number of strings, and these have all been dynamically allocated via malloc() or calloc(). If I just remove or overwrite their pointers, they’ll vanish and cause a memory leak. While I’ve now fixed a large number of leaks thanks to Valgrind, I’m trying to actively avoid any possibility of adding them. Read on for the details… Continue reading “In-place array uniq in C” »

A funny thing happened today…

So, today our ceiling fell in. With about as much warning as that! I was in our kitchen, preparing a cheese toastie for lunch. I opened the oven to put it under the grill to melt, while talking to one of my housemates. Suddenly he yelled “Move… MOVE!” and shoved me back. Up until he did that, I assumed he was just kidding around. And then, a fraction of a second later, the ceiling above the oven collapsed, showering down dust, plaster, bricks, and a bit of old copper piping. A brick went through the space the back of my head had been occupying just a heartbeat before. Needless to say, my plans for lunch were ruined :-( It would have been one hell of an excuse for not handing in my project report on time though! To see pictures, read more… Continue reading “A funny thing happened today…” »