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
- 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
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.
- Precondition
- The behavior is undefined unless
allocator is non-zero, and, if origin is 0, length is also 0.
- Note
- 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:
|<----->| |<----->|
___ ___ ___ ___ ___ ___ ___ ___ ___ ___
| 0 | 1 | 2 | 3 | 4 | | 0 | 1 | 2 | 3 | 4 |
`===^===^===^===^===' `===^===^===^===^==='
^------------ origin ^------------ origin
int length() const
Definition bslma_autodeallocator.h:683