[allocator.members] # 20 Memory management library [[mem]](./#mem) ## 20.2 Memory [[memory]](memory#allocator.members) ### 20.2.10 The default allocator [[default.allocator]](default.allocator#allocator.members) #### 20.2.10.2 Members [allocator.members] [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L1994) Except for the destructor, member functions of the default allocator shall not introduce data races ([[intro.multithread]](intro.multithread "6.10.2 Multi-threaded executions and data races")) as a result of concurrent calls to those member functions from different threads[.](#1.sentence-1) Calls to these functions that allocate or deallocate a particular unit of storage shall occur in a single total order, and each such deallocation call shall happen before the next allocation (if any) in this order[.](#1.sentence-2) [🔗](#lib:allocate,allocator) `constexpr T* allocate(size_t n); ` [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2007) *Mandates*: T is not an incomplete type ([[basic.types.general]](basic.types.general#term.incomplete.type "6.9.1 General"))[.](#2.sentence-1) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2011) *Returns*: A pointer to the initial element of an array of n T[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2015) *Throws*: bad_array_new_length ifnumeric_limits​::​max() / sizeof(T) < n, orbad_alloc if the storage cannot be obtained[.](#4.sentence-1) [5](#5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2021) *Remarks*: The storage for the array is obtained by calling ​::​operator new ([[new.delete]](new.delete "17.6.3 Storage allocation and deallocation")), but it is unspecified when or how often this function is called[.](#5.sentence-1) This function starts the lifetime of the array object, but not that of any of the array elements[.](#5.sentence-2) [🔗](#lib:allocate_at_least,allocator) `constexpr allocation_result allocate_at_least(size_t n); ` [6](#6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2037) *Mandates*: T is not an incomplete type ([[basic.types.general]](basic.types.general#term.incomplete.type "6.9.1 General"))[.](#6.sentence-1) [7](#7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2041) *Returns*: allocation_result{ptr, count}, where ptr is a pointer to the initial element of an array of count T andcount ≥ n[.](#7.sentence-1) [8](#8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2048) *Throws*: bad_array_new_length if numeric_limits​::​max() / sizeof(T) < n, or bad_alloc if the storage cannot be obtained[.](#8.sentence-1) [9](#9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2054) *Remarks*: The storage for the array is obtained by calling ​::​operator new, but it is unspecified when or how often this function is called[.](#9.sentence-1) This function starts the lifetime of the array object, but not that of any of the array elements[.](#9.sentence-2) [🔗](#lib:deallocate,allocator) `constexpr void deallocate(T* p, size_t n); ` [10](#10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2068) *Preconditions*: - [(10.1)](#10.1) If p is memory that was obtained by a call to allocate_at_least, let ret be the value returned andreq be the value passed as the first argument to that call[.](#10.1.sentence-1) p is equal to ret.ptr andn is a value such that req ≤ n ≤ ret.count[.](#10.1.sentence-2) - [(10.2)](#10.2) Otherwise, p is a pointer value obtained from allocate[.](#10.2.sentence-1) n equals the value passed as the first argument to the invocation of allocate which returned p[.](#10.2.sentence-2) [11](#11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2083) *Effects*: Deallocates the storage referenced by p[.](#11.sentence-1) [12](#12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L2087) *Remarks*: Uses​::​operator delete ([[new.delete]](new.delete "17.6.3 Storage allocation and deallocation")), but it is unspecified when this function is called[.](#12.sentence-1)