tensor-0.1.0
|
A reference counting pointer with copy-on-write. More...
Public Types | |
typedef value_type | elt_t |
Type of data pointed to. | |
Public Member Functions | |
elt_t * | begin () |
Retreive the pointer without caring for references (unsafe). More... | |
const elt_t * | begin () const |
Retreive the pointer without caring for references (unsafe). More... | |
const elt_t * | begin_const () const |
Retreive the pointer without caring for references (unsafe). More... | |
const elt_t * | end () const |
Retreive the pointer without caring for references (unsafe). More... | |
elt_t * | end () |
Retreive the pointer without caring for references (unsafe). More... | |
const elt_t * | end_const () const |
Retreive the pointer without caring for references (unsafe). More... | |
RefPointer< elt_t > & | operator= (const RefPointer< elt_t > &p) |
Copy a pointer increasing the reference count. More... | |
void | reallocate (size_t new_size) |
Replace the pointer with newly allocated data. More... | |
size_t | ref_count () const |
Number of references to the internal data. | |
RefPointer () | |
Create an empty reference. | |
RefPointer (size_t new_size) | |
Allocate a pointer of s bytes. More... | |
RefPointer (elt_t *data, size_t size, bool owned=true) | |
Wrap around the given data. | |
RefPointer (const RefPointer< elt_t > &p) | |
Copy constructor that increases the reference count. More... | |
size_t | size () const |
Size of pointed-to data. More... | |
~RefPointer () | |
Destructor that deletes no longer reference data. More... | |
A reference counting pointer with copy-on-write.
This is a pointer that keeps track of whether the same data is shared by other RefPointer structures. It internally keeps a reference counter to store how many pointers look at the data. When the total number of references drops to zero, it destroys the pointed object.
This allows us to have different parts of the code use the same physical (tensor) data, thus avoiding expensive copy operations. The RefPointer behaves thus similar to pointers, but with internal bookkeeping and easier use.
As soon as you manipulate the data (access it through a non-const pointer), it will be silently and transparently copied to another location if the data is shared with other RefPointers. That is, the data encapsulated by a RefPointer is guaranteed not to be modified through side effects.
Note that pointers returned by the various begin() and end() functions are not reference-counted, so you should not store the returned pointers.
Definition at line 49 of file refcount.h.
tensor::RefPointer< value_type >::RefPointer | ( | size_t | new_size | ) |
Allocate a pointer of s bytes.
tensor::RefPointer< value_type >::RefPointer | ( | const RefPointer< elt_t > & | p | ) |
Copy constructor that increases the reference count.
tensor::RefPointer< value_type >::~RefPointer | ( | ) |
Destructor that deletes no longer reference data.
|
inline |
Retreive the pointer without caring for references (unsafe).
Definition at line 70 of file refcount.h.
|
inline |
Retreive the pointer without caring for references (unsafe).
Definition at line 72 of file refcount.h.
|
inline |
Retreive the pointer without caring for references (unsafe).
Definition at line 74 of file refcount.h.
|
inline |
Retreive the pointer without caring for references (unsafe).
Definition at line 78 of file refcount.h.
|
inline |
Retreive the pointer without caring for references (unsafe).
Definition at line 80 of file refcount.h.
|
inline |
Retreive the pointer without caring for references (unsafe).
Definition at line 76 of file refcount.h.
RefPointer<elt_t>& tensor::RefPointer< value_type >::operator= | ( | const RefPointer< elt_t > & | p | ) |
Copy a pointer increasing the reference count.
void tensor::RefPointer< value_type >::reallocate | ( | size_t | new_size | ) |
Replace the pointer with newly allocated data.
|
inline |
Size of pointed-to data.
Definition at line 83 of file refcount.h.