Created
October 19, 2019 05:32
-
-
Save giraphics/fef93c06b1b01c532bbf7034fd5c8139 to your computer and use it in GitHub Desktop.
Unique Pointer CustomDeleter
This file contains hidden or 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 <class T> | |
struct GfxCircularQueueDefaultDeleter | |
{ | |
void operator()(T* p_Buffer) const | |
{ | |
LOG_INFO("Circlular queue array deleted, queue is empty now...."); | |
delete p_Buffer; | |
} | |
}; | |
// The circular buffer is generic implementation to store items. The item are enqueue from Head(Front) and get from Tail(Rear). | |
// Ring buffer does not owns the objects. Valid items are always within Head and Tail, there diff make the buffer size. | |
template <class T> | |
class GfxCircularQueue | |
{ | |
public: | |
explicit GfxCircularQueue(size_t p_Size, UiGfxUInt p_LazyShrinkThreshold = UINT_MAX); | |
protected: | |
std::unique_ptr<T[], GfxCircularQueueDefaultDeleter<T>> m_Buffer; | |
}; | |
template<class T> | |
GfxCircularQueue<T>::GfxCircularQueue(size_t p_Size, UiGfxUInt p_LazyShrinkThreshold/*=UINT_MAX*/) | |
: m_Buffer(std::unique_ptr<T[], GfxCircularQueueDefaultDeleter<T>>(new T[p_Size], GfxCircularQueueDefaultDeleter<T>())) | |
{ | |
memset(m_Buffer.get(), 0, sizeof(T) * p_Size); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment