NF_SHARE_PTR is a smart pointer offered by the open source C++ framework, NFrame. It helps manage the memory allocation of objects to avoid memory leaks or dangling pointers.
Example 1: Sharing Resources In multi-threaded programs or when you want to share resource ownerships with other objects, you can use NF_SHARE_PTR. When an object with shared ownership goes out of scope, the resource will be released once there are no more shared ownerships.
// Create a shared pointer to an instance of MyObject NF_SHARE_PTR myObj = NF_SHARE_PTR(new MyObject());
// Create a copy of the shared pointer to the same object NF_SHARE_PTR myObjCopy = myObj;
// Both pointers share the same object myObj->doSomething(); myObjCopy->doSomething();
// Once two shared pointers go out of scope, // the resource is released automatically
Example 2: Custom Deleter Function You can define a custom deleter function that is called when a shared pointer goes out of scope. This can be useful when you have to release the resource in a specific way that is not managed by the shared pointer's default deleter function.
// Write a custom deleter function for MyResource void customDeleter(MyResource* res) { // Clean up resource releaseResource(res); }
// Create a shared pointer with custom deleter NF_SHARE_PTR myRes = NF_SHARE_PTR(new MyResource, customDeleter);
// Once the shared pointer goes out of scope, // myResource object will be cleaned up using the custom deleter function.
C++ (Cpp) NF_SHARE_PTR::First - 27 examples found. These are the top rated real world C++ (Cpp) examples of NF_SHARE_PTR::First extracted from open source projects. You can rate examples to help us improve the quality of examples.