Next : , Previous : Adaptors, Top : Table of  Contents


Memory Handling Primitives

T* allocate (ptrdiff_t n, T*) Function
To obtain a typed pointer to an uninitialized memory buffer of a given size the following function is defined:

template  inline T* allocate(ptrdiff_t n, T*); // n >= 0
The size (in bytes) of the allocated buffer is no less than n*sizeof(T). For every memory model there is a corresponding allocate template function defined with the first argument type being the distance type of the pointers in the memory model.

For example, if a compilation system supports __huge pointers with the distance type being long long, the following template function is provided:

template inline T __huge* allocate(long long n, T __huge *);

deallocate (T* buffer) Function
construct (T1* p, const T2& value) Function
destroy (T* pointer) Function

Also, the following functions are provided:

template inline void deallocate(T* buffer);

template inline void construct(T1* p, const T2& value) {
    new (p) T1(value);
}

template inline void destroy(T* pointer) {
    pointer->~T();
}

deallocate frees the buffer allocated by allocate. For every memory model there are corresponding deallocate, construct and destroy template functions defined with the first argument type being the pointer type of the memory model.

pair<T*, ptrdiff_t> get_temporary_buffer (ptrdiff_t n, T*) Function
void return_temporary_buffer (T* p) Function

template pair get_temporary_buffer(ptrdiff_t n, T*);

template void return_temporary_buffer(T* p);

get_temporary_buffer finds the largest buffer not greater than n*sizeof(T), and returns a pair consisting of the address and the capacity (in the units of sizeof(T)) of the buffer. return_temporary_buffer returns the buffer allocated by get_temporary_buffer.


 

Top