kdungs/cpp-neat — pull request #1 by dbroady1 (2014-12-05 15:50:05+00:00)
Title: New example for dealing with return parameters

I just read your blog post about 'Memory management of C libraries in C++' (https://dun.gs/posts/2014-11-06-c-cpp-memory.html).

I thought I would let you know a little technique I found on StackOverflow for dealing with C APIs that return memory in out parameters. It works on G++-4.8 & MSVC 2013. Not sure about older compilers. Only requirement is std::unique_ptr must be available.

Also, I wanted to let you know that if you declare a function object for the deleter function, then you don't have to initialize the std::unique_ptr explicitly. The default constructor will setup everything correctly.

Taken from http://stackoverflow.com/questions/22095214/how-to-use-unique-ptr-with-data-allocated-within-a-c-library
specifically the response from 'Mooing Duck' on Feb 28, 2014 at 18:37

I extended the ptrptr_type struct to handle arrays as well.