-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
A point often raised by people is that RAII isn't always possible.
One such example using Vulkan:
- A VkBuffer object may be created on a VkDevice.
- To destroy the buffer you need both the VkBuffer and VkDevice:
void vkDestroyBuffer(
VkDevice device,
VkBuffer buffer,
const VkAllocationCallbacks* pAllocator);Imagine an owner that holds one VkDevice handle and a number of VkBuffers.
In an ordinary situation, the owner can iterate over the VkBuffer container and call vkDestroyBuffer using its VkDevice member.
Each VkBuffer's memory footprint is simply the size of its handle type, as the owner holds the VkDevice handle.
In RAII as I understand it, using a unique_ptr would require each such instance owned by the aforementioned owner hold the same VkDevice handle, effectively doubling the memory footprint of each handle.
One solution I could think of is to contain the VkDevice in a Singleton (the kind I.3 Avoid singletons declares an exception) but that is quite restricting and a whole thing with regards to the lifetime of the VkDevice.
I was wondering if I somehow missed existing discussions or advice on this instance?
Thanks!