"Zero-overhead" objects pool

Sometimes I just feel stupid. For the longest time, whenever I implemented an object pool, I always had some kind of variable length array to store my list of free objects in additional to the backing memory of the objects. This meant that I had additional memory allocations to store and potentially resize this list. struct Pool { Type * backing_memory; DynArray<Type *> free_objects; // Some more housekeeping stuff }; Today I just realized that, as long as the objects are larger than the size of a pointer (which is pretty much always the case), you can just store the pointer to the next free object in it and essentially build a linked list.
Read more

Find lowest set bit

So today I was working with Vulkan and needed to somehow stringify the state of a VkDebugReportFlagsEXT. I was too lazy to concatenate strings so I decided to only take into account the first bit, and ignore the rest (this is for internal debugging purposes so… meh). So I needed a way to find the lowest set bit in an unsigned integer. Here’s what I came up with: uint find_lowest_set_bit(uint n) { return (~(n - 1)) & n; } Now for a step-by-step explanation of what’s going on, with A = 01001100.
Read more

Entity-Component Part 2: Entities

In the second part of this article series on entity-component systems, we are going to take a look at how entities can be managed. Don’t forget to read part one which explained the very basics of the entity-component paradigm. Today we are finally going to start writing some actual code on entities management. The manager Some implementation define the manager (the big class reponsible for handling entities and their components) as a singleton.
Read more

Entity-Component Part 1: What? Why? How?

So you have just finished developing the class for the zombie knight of your upcoming game. His animation is smooth, his AI perfect, you are proud. He had a lot in common with the mad cleric you developed two weeks ago, except for the way he fights, so you just copy-pasted the parts that were similar. You are not going to modify those any time soon anyway, are you? The next day, your friend comes over with a great idea for a new kind of magic for the player.
Read more