# pqxx::internal::PQAlloc< T > Class Template Reference

Reference-counted smart pointer to libpq-allocated object. More...

`#include <util.hxx>`

Inheritance diagram for pqxx::internal::PQAlloc< T >:

[legend]

List of all members.

## Public Types
typedef T | content_type
## Public Member Functions
| PQAlloc () throw ()
| PQAlloc (const PQAlloc &rhs) throw ()
| ~PQAlloc () throw ()
PQAlloc & | operator= (const PQAlloc &rhs) throw ()
| PQAlloc (T *obj) throw ()
| Assume ownership of a pointer.
void | swap (PQAlloc &rhs) throw ()
PQAlloc & | operator= (T *obj) throw ()
| operator bool () const throw ()
| Is this pointer non-null?
bool | operator! () const throw ()
| Is this pointer null?
T * | operator-> () const throw ( std ::logic_error)
| Dereference pointer.
T & | operator* () const throw ( std ::logic_error)
| Dereference pointer.
T * | c_ptr () const throw ()
| Obtain underlying pointer.
void | clear () throw ()
template<>
void | freemem () throw()
template<>
void | freemem () throw()

## Detailed Description

### template<typename T>
class pqxx::internal::PQAlloc< T >

Reference-counted smart pointer to libpq-allocated object.

Keep track of a libpq-allocated object, and free it once all references to it have died.

If the available PostgreSQL development files supply `PQfreemem()` or `PQfreeNotify()`, this is used to free the memory. If not, free() is used instead. This matters on Windows, where memory allocated by a DLL must be freed by the same DLL.

Warning:
  Copying, swapping, and destroying PQAlloc objects that refer to the same underlying libpq-allocated block is not thread-safe. If you wish to pass reference-counted objects around between threads, make sure that each of these operations is protected against concurrency with similar operations on the same object--or other copies of the same object.

## Member Typedef Documentation

template<typename T>

typedef T pqxx::internal::PQAlloc< T >::content_type

## Constructor & Destructor Documentation

template<typename T>

pqxx::internal::PQAlloc< T >::PQAlloc | ( |  | ) | throw ()

template<typename T>

pqxx::internal::PQAlloc< T >::PQAlloc | ( | const PQAlloc< T > & | rhs | ) | throw ()

template<typename T>

pqxx::internal::PQAlloc< T >::~PQAlloc | ( |  | ) | throw ()

template<typename T>

pqxx::internal::PQAlloc< T >::PQAlloc | ( | T * | obj | ) | throw ()`[explicit]`

Assume ownership of a pointer.

Warning:
  Don't to this more than once for a given object!

## Member Function Documentation

template<typename T>

T* pqxx::internal::PQAlloc< T >::c_ptr | ( |  | ) | const throw ()

Obtain underlying pointer.

Ownership of the pointer's memory remains with the PQAlloc object

Reimplemented in pqxx::binarystring.

Referenced by pqxx::connection_base::esc_raw(), and pqxx::escape_binary().

template<typename T>

void pqxx::internal::PQAlloc< T >::clear | ( |  | ) | throw ()

Reimplemented in pqxx::result.

template<>

void pqxx::internal::PQAlloc< pq::PGnotify >::freemem | ( |  | ) | throw()

References pqxx::internal::freemem_notif().

template<>

void pqxx::internal::PQAlloc< result_data >::freemem | ( |  | ) | throw()

References pqxx::internal::freemem_result_data().

template<typename T>

pqxx::internal::PQAlloc< T >::operator bool | ( |  | ) | const throw ()

Is this pointer non-null?

template<typename T>

bool pqxx::internal::PQAlloc< T >::operator! | ( |  | ) | const throw ()

Is this pointer null?

template<typename T>

T& pqxx::internal::PQAlloc< T >::operator* | ( |  | ) | const throw ( std ::logic_error)

Dereference pointer.

Throws a logic_error if the pointer is null.

template<typename T>

T* pqxx::internal::PQAlloc< T >::operator-> | ( |  | ) | const throw ( std ::logic_error)

Dereference pointer.

Throws a logic_error if the pointer is null.

Referenced by pqxx::internal::PQAlloc< internal::result_data >::operator*().

template<typename T>

PQAlloc& pqxx::internal::PQAlloc< T >::operator= | ( | T * | obj | ) | throw ()

template<typename T>

PQAlloc& pqxx::internal::PQAlloc< T >::operator= | ( | const PQAlloc< T > & | rhs | ) | throw ()

template<typename T>

void pqxx::internal::PQAlloc< T >::swap | ( | PQAlloc< T > & | rhs | ) | throw ()

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

- util.hxx