Fawkes API
Fawkes Development Version
|
Automatically free memory on destruction. More...
#include <>>
Public Member Functions | |
MemAutoFree (void *ptr) | |
Constructor. More... | |
~MemAutoFree () | |
Destructor. More... | |
void | release () |
Release ownership. More... | |
void | reset (void *new_ptr) |
Reset pointer to a different one, This will free the pointer hold up to this call and will replace it with new_ptr. More... | |
Automatically free memory on destruction.
This class can be used to free memory on destruction of the object. This is similar to many use cases of std::auto_ptr, with the difference that it calls free() to release the memory instead of delete, therefore it is meant to be used with classical memory allocations, e.g. C strings. In effect the instance of MemAutoFree takes ownership of the passed pointer.
Definition at line 32 of file autofree.h.
fawkes::MemAutoFree::MemAutoFree | ( | void * | ptr | ) |
Constructor.
ptr | pointer to delete on destruct |
Definition at line 45 of file autofree.cpp.
fawkes::MemAutoFree::~MemAutoFree | ( | ) |
Destructor.
Destroys the memory chunk unless it has been released before.
Definition at line 54 of file autofree.cpp.
void fawkes::MemAutoFree::release | ( | ) |
Release ownership.
The instance no longer owns the pointer and memory will not be deleted on destruction.
Definition at line 65 of file autofree.cpp.
void fawkes::MemAutoFree::reset | ( | void * | new_ptr | ) |
Reset pointer to a different one, This will free the pointer hold up to this call and will replace it with new_ptr.
It is verified that the old and new pointers are different, nothing will be done if they are the same.
new_ptr | new pointer to own |
Definition at line 78 of file autofree.cpp.