Fawkes API  Fawkes Development Version
fawkes::MemAutoFree Class Reference

#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...
 
void * operator* () const
 Access memory pointer. 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 35 of file autofree.h.

Constructor & Destructor Documentation

◆ MemAutoFree()

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

Constructor.

Parameters
ptrpointer to delete on destruct

Definition at line 49 of file autofree.cpp.

◆ ~MemAutoFree()

fawkes::MemAutoFree::~MemAutoFree ( )

Destructor.

Destroys the memory chunk unless it has been released before.

Definition at line 57 of file autofree.cpp.

Member Function Documentation

◆ operator*()

void * fawkes::MemAutoFree::operator* ( ) const

Access memory pointer.

Returns
pointer to memory, maybe NULL

Definition at line 92 of file autofree.cpp.

◆ 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 68 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 80 of file autofree.cpp.


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