Click here to Skip to main content
15,889,595 members
Articles / Desktop Programming / Win32

Using C++ Move Semantics to Manage Pointers to Externally Allocated Memory

Rate me:
Please Sign up or sign in to vote.
4.97/5 (19 votes)
3 Nov 2022MIT10 min read 10.9K   98   20  
The win32 subsystem often returns pointers to objects that need to be deallocated by the caller. In this article, I show a way to do this reliably and in an exception-safe manner.
The win32 subsystem often returns pointers to objects that need to be deallocated by the caller, by calling LocalFree. This places the burden of memory management on the caller. However, manually doing this is tedious and errorprone. And on top of it, it is fundamentally exception-unsafe. In this article, I show a way to do this reliably and in an exception-safe manner by implementing a smart pointer that uses 'move' semantics.

Views

Daily Counts

Downloads

Weekly Counts

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Software Developer
Belgium Belgium
I am a former professional software developer (now a system admin) with an interest in everything that is about making hardware work. In the course of my work, I have programmed device drivers and services on Windows and linux.

I have written firmware for embedded devices in C and assembly language, and have designed and implemented real-time applications for testing of satellite payload equipment.

Generally, finding out how to interface hardware with software is my hobby and job.

Comments and Discussions