smart_pointer(9)

NAME

occurence, smart_pointer - memory management

DESCRIPTION

Here is a convenient way to implement a true copy semantc,
by using shallow copies and reference counting, in order to
minimise memory copies.
This concept is generally related to the smart pointer method for managing memory.

The true semantic copy is defined as follows: if an object
A is assigned to
B, such as A = B, every further modification on A or B
does not modify the other.

IMPLEMENTATION

template <class T>
class smart_pointer {
public:

// allocators:
smart_pointer (T* p = 0);
smart_pointer (const smart_pointer&);
~smart_pointer ();
smart_pointer& operator= (const smart_pointer&);
// accessors:

const T* pointer () const;
const T& data () const;
const T* operator-> () const;
const T& operator* () const;
// modifiers:

T* pointer ();
T* operator-> ();
T& data ();
T& operator* ();
// implementation:
private:
struct counter {
T* _p;
int _n;
counter (T* p = 0);
~counter ();
int operator++ ();
int operator-- ();
};
counter *_count;
};
Copyright © 2010-2025 Platon Technologies, s.r.o.           Home | Man pages | tLDP | Documents | Utilities | About
Design by styleshout