BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslma::AutoDeallocator< ALLOCATOR > Class Template Reference

#include <bslma_autodeallocator.h>

Public Member Functions

template<class TYPE >
 AutoDeallocator (TYPE **origin, ALLOCATOR *allocator, int length=0)
 
 AutoDeallocator (void **origin, ALLOCATOR *allocator, int length=0)
 
 ~AutoDeallocator ()
 
void operator++ ()
 
void operator-- ()
 
void release ()
 
template<class TYPE >
void reset (TYPE **origin)
 
void reset (void **origin)
 
void setLength (int length)
 
int length () const
 

Detailed Description

template<class ALLOCATOR>
class bslma::AutoDeallocator< ALLOCATOR >

This class implements a range proctor that, unless its release method has previously been invoked, automatically deallocates the contiguous sequence of managed memory blocks upon its own destruction by invoking the deallocate method of an allocator (or pool) of parameterized ALLOCATOR type supplied to it at construction. Each of the managed memory blocks must have been supplied by this allocator (or pool), which must remain valid throughout the lifetime of the range proctor. Note that when the length of this object is non-zero, it must refer to a non-null array of memory blocks.

See bslma_autodeallocator

Constructor & Destructor Documentation

◆ AutoDeallocator() [1/2]

template<class ALLOCATOR >
template<class TYPE >
bslma::AutoDeallocator< ALLOCATOR >::AutoDeallocator ( TYPE **  origin,
ALLOCATOR *  allocator,
int  length = 0 
)
inline

Create an auto deallocator to manage a sequence of memory blocks at the specified origin, and that uses the specified allocator to deallocate the sequence of memory blocks managed by this range proctor (if not released – see release) upon destruction. Optionally specify length to define its range, which by default is empty (i.e., length = 0). The sequence of memory blocks may extend in either direction from origin. A positive length represents the sequence of memory blocks starting at origin and extending "up" to length (not including the memory block at the index position origin + length). A negative length represents the sequence of memory blocks starting at one position below origin and extending "down" to the absolute value of length (including the memory block at index position origin + length). If length is 0, then this range proctor manages no memory blocks. If origin is non-zero, all memory blocks within the proctored range (if any) must be supplied by allocator. The behavior is undefined unless allocator is non-zero, and, if origin is 0, length is also 0. Note that when length is non-positive, the memory block at the origin is not managed by this range proctor. For example, if origin is at the index position 2, a length of 2 signifies that the memory blocks at positions 2 and 3 are managed, whereas a length of -2 signifies that the memory blocks at positions 0 and 1 are managed:

length = -2 length = 2
|<----->| |<----->|
___ ___ ___ ___ ___ ___ ___ ___ ___ ___
| 0 | 1 | 2 | 3 | 4 | | 0 | 1 | 2 | 3 | 4 |
`===^===^===^===^===' `===^===^===^===^==='
^------------ origin ^------------ origin
int length() const
Definition bslma_autodeallocator.h:667

◆ AutoDeallocator() [2/2]

template<class ALLOCATOR >
bslma::AutoDeallocator< ALLOCATOR >::AutoDeallocator ( void **  origin,
ALLOCATOR *  allocator,
int  length = 0 
)
inline

◆ ~AutoDeallocator()

template<class ALLOCATOR >
bslma::AutoDeallocator< ALLOCATOR >::~AutoDeallocator ( )
inline

Destroy this range proctor and deallocate the contiguous sequence of memory blocks it manages (if any) by invoking the deallocate method of the allocator (or pool) supplied at construction on each memory block. Note that the order in which the managed memory blocks are deallocated is undefined.

Member Function Documentation

◆ length()

template<class ALLOCATOR >
int bslma::AutoDeallocator< ALLOCATOR >::length ( ) const
inline

Return the (signed) length of the sequence of memory blocks managed by this proctor.

◆ operator++()

template<class ALLOCATOR >
void bslma::AutoDeallocator< ALLOCATOR >::operator++ ( )
inline

Increase by one the (signed) length of the sequence of memory blocks managed by this range proctor. The behavior is undefined unless the origin of the sequence of memory blocks managed by this proctor is non-zero. The behavior is undefined unless the origin or this range proctor is non-zero. Note that if the length of this proctor is currently negative, the number of managed memory blocks will decrease by one, whereas if the length is non-negative, the number of managed memory blocks will increase by one.

◆ operator--()

template<class ALLOCATOR >
void bslma::AutoDeallocator< ALLOCATOR >::operator-- ( )
inline

Decrease by one the (signed) length of the sequence of memory blocks managed by this range proctor. The behavior is undefined unless the origin of the sequence of memory blocks managed by this proctor is non-zero. The behavior is undefined unless the origin or this range proctor is non-zero. Note that if the length of this proctor is currently positive, the number of managed memory blocks will decrease by one, whereas if the length is non-positive, the number of managed memory blocks will increase by one.

◆ release()

template<class ALLOCATOR >
void bslma::AutoDeallocator< ALLOCATOR >::release ( )
inline

Release from management the sequence of memory blocks currently managed by this range proctor by setting the length of the managed sequence to 0. All memory blocks currently under management will become unmanaged (i.e., when the proctor goes out of scope and it was not assigned another sequence of memory blocks to manage by invoking reset, no memory blocks will be deallocated). If no memory blocks are currently being managed, this method has no effect. Note that the origin is not affected.

◆ reset() [1/2]

template<class ALLOCATOR >
template<class TYPE >
void bslma::AutoDeallocator< ALLOCATOR >::reset ( TYPE **  origin)
inline

Set the specified origin as the origin of the sequence of memory blocks to be managed by this range proctor. The behavior is undefined unless origin is non-zero. Note that the length of the sequence of memory blocks managed by this proctor is not affected, and setLength should be invoked if the managed range is different from the previously managed sequence of memory blocks. Also note that this method releases any previously-managed memory blocks from management (without deallocating them), and so may be called with or without having called release when reusing this object.

◆ reset() [2/2]

template<class ALLOCATOR >
void bslma::AutoDeallocator< ALLOCATOR >::reset ( void **  origin)
inline

◆ setLength()

template<class ALLOCATOR >
void bslma::AutoDeallocator< ALLOCATOR >::setLength ( int  length)
inline

Set the (signed) length of the sequence of memory blocks managed by this range proctor to the specified length. The behavior is undefined unless the origin of this range proctor is non-zero.


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