Skip to content

Instantly share code, notes, and snippets.

@maxattack
Last active December 20, 2015 02:49
Show Gist options
  • Save maxattack/6058918 to your computer and use it in GitHub Desktop.
Save maxattack/6058918 to your computer and use it in GitHub Desktop.
template<typename T, int N>
class AnonymousPool {
private:
uint32_t mCount;
T mRecords[N];
public:
AnonymousPool() : mCount(0) {
}
int count() const { return mCount; }
T* begin() { return mRecords; }
T* end() { return mRecords+mCount; }
T* takeOut() {
ASSERT(mCount < N);
mCount++;
return mRecords + (mCount-1);
}
void putBack(T* t) {
int n = t - mRecords;
ASSERT(n < mCount);
mCount--;
mRecords[n] = mRecords[mCount];
}
void drain() {
mCount = 0;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment