STXXL
1.4-dev
|
This class takes a shared pointer, increments its reference count and wraps it in a way that the resulting object can be copied, dumped to disk, and destroyed without affecting the refcount.
When the object is retrieved from disk and recreated on internal memory, it will still hold a reference to the same memory block and can be used right away by calling the "get" method or unwrapped with the "unwrap" method to decrement the refcount.
In the context of this template, a shared pointer is an object of a class P that fulfills the following requirements:
Both the Boost and c++0x implementations of shared_ptr fulfill these requirements. At the moment of writing the author is not aware of any implementations of shared pointers that can't be used with this wrapper.
Definition at line 46 of file external_shared_ptr.h.
Public Member Functions | |
external_shared_ptr () | |
This constructor needs to be defined so that the [] operator in maps and hash tables works. More... | |
external_shared_ptr (P ptr) | |
Copy the pointer to internal storage and increment the refcount (the destructor never gets called). More... | |
P | get () const |
If this is called after unwrap() the behaviour is undefined. More... | |
bool | operator== (const external_shared_ptr &x) const |
void | unwrap () |
Call the destructor to decrement the refcount. More... | |
Private Attributes | |
char | data [sizeof(P)] |
We store the pointer like this so that the refcount does not get incremented when the wrapper is copy-constructed, or decremented when the wrapper is destroyed. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const external_shared_ptr &p) |
Output contained data items. More... | |
|
inline |
This constructor needs to be defined so that the [] operator in maps and hash tables works.
If unwrap() or get() are called for an object constructed this way the behavior is undefined.
Definition at line 68 of file external_shared_ptr.h.
|
inline |
Copy the pointer to internal storage and increment the refcount (the destructor never gets called).
Definition at line 75 of file external_shared_ptr.h.
|
inline |
If this is called after unwrap() the behaviour is undefined.
Definition at line 93 of file external_shared_ptr.h.
|
inline |
Definition at line 99 of file external_shared_ptr.h.
References stxxl::external_shared_ptr< P >::data.
|
inline |
Call the destructor to decrement the refcount.
If this is called more than once the results are undefined.
Definition at line 84 of file external_shared_ptr.h.
|
friend |
Output contained data items.
Definition at line 109 of file external_shared_ptr.h.
|
private |
We store the pointer like this so that the refcount does not get incremented when the wrapper is copy-constructed, or decremented when the wrapper is destroyed.
The whole external_shared_ptr object will be aligned by the compiler to a multiple of its size. The size of the object is sizeof(P) as the buffer is its only member. The buffer is placed in the class at offset 0 so the alignment of the stored P should be alright without any additional hints.
Definition at line 60 of file external_shared_ptr.h.
Referenced by stxxl::external_shared_ptr< P >::operator==().