Last active
December 20, 2015 02:49
-
-
Save maxattack/6058918 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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