Original Post
So I have numerical Ids in my engine for things that are created and destroyed often. Right now when I assign a new id I use the following code: Which honestly, for it's simplicity isn't bad, I get what, over 4 billion Ids before this method craps out? Probably not gonna hit that. But, for cleanliness sake, I want to build a manager which will keep track of Ids as they are assigned and more importantly, freed, so freed ones can be used again. I began thinking about this and the first few things that flew through my mind were too memory hungry. Then I came up with an idea of having my IdManager class maintain a large bit field. So if I wanted to support Ids 0 - 7 I would have 8 bits in a bit vector like so: 11100110 This would mean ids: 1, 2, 3, 6, 7 are currently assigned and ids: 4, 5, 8 are currently free. Thus requiring MUCH less memory. After thinking this up and remembering there are much much smarter people then me on here, I decided to see what you guys thought, see how this is commonly done.
uint32_t IdManager::getNextId() {
return ++m_iNextId;
}