pair<T1,T2>& y); The equality operator. The return value is true if and only the first elements of x and y are equal, and the second elements of x and y are equal. This operator may only be used if both T1 and T2 are EqualityComparable . This is a global function, not a member function.
template <class T1, class T2> bool operator<(const pair<T1,T2>& x, const pair<T1,T2>& y); The comparison operator. It uses lexicographic comparison: the return value is true if the first element of x is less than the first element of y, and false if the first element of y is less than the first element of x. If neither of these is the case, then operator< returns the result of comparing the second elements of x and y. This operator may only be used if both T1 and T2 are LessThanComparable . This is a global function, not a member function.
template <class T1, class T2> pair<T1, T2> make_pair(const T1& x, const T2& x) Equivalent to pair<T1, T2>(x, y). This is a global function, not a member function. It exists only for the sake of convenience.
See also

Assignable, Default Constructible, LessThan Comparable

Memory Allocation

Classes

Allocators

Category: allocators

Component type: overview

Summary

Allocators encapsulate allocation and deallocation of memory. They provide a low-level interface that permits efficient allocation of many small objects; different allocator types represent different schemes for memory management.

Note that allocators simply allocate and deallocate memory, as opposed to creating and destroying objects. The STL also includes several low-level algorithms for manipulating uninitialized memory.

Note also that allocators do not attempt to encapsulate multiple memory models. The C++ language only defines a single memory model (the difference of two pointers, for example, is always ptrdiff_t), and this memory model is the only one that allocators support. This is a major change from the definition of allocators in the original STL. [1]

Description

The details of the allocator interface are still subject to change, and we do not guarantee that specific member functions will remain in future versions. You should think of an allocator as a 'black box'. That is, you may select a container's memory allocation strategy by instantiating the container template with a particular allocator [2], but you should not make any assumptions about how the container actually uses the allocator.

The available allocators are as follows. In most cases you shouldn't have to worry about the distinction: the default allocator, alloc, is usually the best choice.

alloc The default allocator. It is thread-safe, and usually has the best performance characteristics.
pthread_alloc A thread-safe allocator that uses a different memory pool for each thread; you can only use pthread_alloc if your operating system provides pthreads. Pthread_alloc is usually faster than alloc, especially on multiprocessor systems. It can, however, cause resource fragmentation: memory deallocated in one thread is not available for use by other threads.
single_client_alloc A fast but thread-unsafe allocator. In programs that only have one thread, this allocator might be faster than alloc.
malloc_alloc An allocator that simply uses the standard library function malloc. It is thread- safe but slow; the main reason why you might sometimes want to use it is to get more useful information from bounds-checking or leak-detection tools while you are debugging.
Examples

vector<double> V(100, 5.0); // Uses the default allocator.

vector<double, single_client_alloc> local(V.begin(), V.end());

Concepts

• Allocator

Types

• alloc

• pthread_alloc

• single_client_alloc

• malloc_alloc

• raw_storage_iterator

Functions
Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату