www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Question about wrapping raw C pointers from D

reply "Rusty D. Shackleford" <nanr9d gmail.com> writes:
Hi, in C++ I can use smart pointers to wrap raw pointers with 
custom deleter to automatically manage C resources. Is there 
anything like this in D?
May 29 2014
parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 05/29/2014 09:38 PM, Rusty D. Shackleford wrote:

 Hi, in C++ I can use smart pointers to wrap raw pointers with custom
 deleter to automatically manage C resources. Is there anything like this
 in D?
1) Structs provide RAII: struct S { // ... ~this() { // cleanup } } 2) catch and finally clauses can be used 3) scope(failure), scope(exit), and scope(success): { auto r = allocateSomeResource(); scope(exit) deallocateSomeResource(r); // ... } Ali
May 29 2014