Any class that fulfills the "allocator requirements" can be used as an allocator. In particular, a class codice_1 capable of allocating memory for an object of type codice_2 must provide the types codice_3, codice_4, codice_5, codice_6, and codice_7 for generically declaring objects and references (or pointers) to objects of type codice_2. It should also provide type codice_9, an unsigned type which can represent the largest size for an object in the allocation model defined by codice_1, and similarly, a signed integral codice_11 that can represent the difference between any two pointers in the allocation model.

Although a conforming standard library implementation is allowed to assume that the allocator's codice_3 and codice_4 are simply typedefs for codice_14 and codice_15, library implementors are encouraged to support more general allocators.

An allocator, codice_1, for objects of type codice_2 must have a member function with the signature codice_18. This function returns a pointer to the first element of a newly allocated array large enough to contain codice_19 objects of type codice_2; only the memory is allocated, and the objects are not constructed. Moreover, an optional pointer argument (that points to an object already allocated by codice_1) can be used as a hint to the implementation about where the new memory should be allocated in order to improve locality. However, the implementation is free to ignore the argument.

The corresponding codice_22 member function accepts any pointer that was returned from a previous invocation of the codice_23 member function and the number of elements to deallocate (but not destruct).

The codice_24 member function returns the largest number of objects of type codice_2 that could be expected to be successfully allocated by an invocation of codice_23; the value returned is typically codice_27. Also, the codice_28 member function returns an codice_3 denoting the address of an object, given an codice_5.

Object construction and destruction is performed separately from allocation and deallocation. The allocator is required to have two member functions, codice_31 and codice_32, which handles object construction and destruction, respectively. The semantics of the functions should be equivalent to the following:

template <typename T>

template <typename T>

The above code uses the placement codice_33 syntax, and calls the destructor directly.

Allocators should be copy-constructible. An allocator for objects of type codice_2 can be constructed from an allocator for objects of type codice_35. If an allocator, codice_1, allocates a region of memory, codice_37, then codice_37 can only be deallocated by an allocator that compares equal to codice_1.

Allocators are required to supply a template class member codice_40, which enables the possibility of obtaining a related allocator, parameterized in terms of a different type. For example, given an allocator type codice_41 for objects of type codice_42, a related allocator type for objects of type codice_43 could be obtained using codice_44.

নিজস্ব অ্যালোকেটরসমূহ
সি++১১ এ অ্যালোকেটরের উন্নতি
আবশ্যকতা
পটভূমি