logoalt Hacker News

throwitaway222 • today at 4:24 PM • 2 replies • view on HN

I remember back in the day in Windows C++ programming everything was a HANDLE memory is probably not serving me, but they were all really just void* renamed. And you use them with various win32 functions I guess to keep things straight. I don't miss those days.


Replies

delta_p_delta_x • today at 5:05 PM

> but they were all really just void* renamed

The good thing is that all of these can and have been quite neatly put into RAII[1] or some memory arena with custom deleters which use the Win32 functions. One could manually `delete` those handles, but there be dragons. Vulkan does something similar; everything is a VkSomething handle. They may just be pointers directly exposed by the driver, but even so, users are explicitly supposed to use vkDeleteSomething functions to delete them.

[1]: https://github.com/microsoft/wil

andrewshadura • today at 4:50 PM

Famously Win16 API required locking memory allocations to be able to access them by a pointer. Unlocked allocations could be moved by the OS.