Fawkes API  Fawkes Development Version
fawkes::MemAutoFree Class Reference

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...
 

Detailed Description

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.

Author
Tim Niemueller

Definition at line 32 of file autofree.h.

Constructor & Destructor Documentation

◆ MemAutoFree()

fawkes::MemAutoFree::MemAutoFree ( void *  ptr)

Constructor.

Parameters
ptrpointer to delete on destruct

Definition at line 45 of file autofree.cpp.

◆ ~MemAutoFree()

fawkes::MemAutoFree::~MemAutoFree ( )

Destructor.

Destroys the memory chunk unless it has been released before.

Definition at line 54 of file autofree.cpp.

Member Function Documentation

◆ release()

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.

◆ reset()

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.

Parameters
new_ptrnew pointer to own

Definition at line 78 of file autofree.cpp.


The documentation for this class was generated from the following files: