SmartPointer is C++ project and its aim is to ensure that resource acquisition occurs at the same time that the object is initialized, so that all resources for the object are created and made ready in one line of code. In general the main goal is to give ownership of any heap-allocated resource—for example, dynamically-allocated memory or system object handles—to a stack-allocated object whose destructor contains the code to delete or free the resource. Here pointer(s) of any type is/are first initialized then pass those pointer(s) to SmartPointer immediately.
SmartPointer uses templates, it means that you can play with any type pointer(s). In order to keep track of the number of calls made to SmartPointer RefCount.cpp class is written and it contains two methods i-e AddRef and ReleaseRef, which increment the count on adding pointer(s) and decrement this count by releasing pointer(s) respectively. For testing purpose I have added CubeSample class, which calculate density of any metal in order to find the purity of metal. This class is used in my incoming opensource C++ game engine sdk. Last but not the least Demo.cpp class present the actual usage of this library. Rest of the code is straight forward.
SmartPointer prevent situations of memory leaks as memory deallocation is done automatically. i-e object can be destroyed automatically. Put in simple words the object controlled by a smart pointer is automatically destroyed. SmartPointers also eliminate dangling pointers or wild pointers by postponing destruction until the object is no longer in use.
If you are using svn you need to repo my repository using the command Use this command to anonymously check out the latest project source code:
svn checkout https://github.com/ziaagikian/Smart-Pointer smartpointer-read-only
once the source code is downlaoded build import to your favourite ide, like eclipse cdt.
You can implement SmartPointer as per your requirment i-e when you are dealing in pointers and concerned about its memory management. You can check demo C++ example in the source named as Demo.cpp. Following code show how use SmartPointer.
/********************* Smart Pointer in action ***************************/
// Initialize any Raw Pointer
T *t = new T;// Where T is template and can be any class.
//Pass t pointer to SmartPointer
SPointer<T> obj(t);
/***************** End of Smart Pointer in action ************************/
SmartPointer is licensed under the Apache License 2.0.
Please report bugs, tell me about your problems or request features by creating issues on GitHub.