Skip to content

Instantly share code, notes, and snippets.

@giraphics
Created October 19, 2019 05:31
Show Gist options
  • Save giraphics/dad28d279ab4e02859b9c4cb29a76ea1 to your computer and use it in GitHub Desktop.
Save giraphics/dad28d279ab4e02859b9c4cb29a76ea1 to your computer and use it in GitHub Desktop.
Unique Pointer CustomDeleter
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