[mem.res.global]

# 20 Memory management library [[mem]](./#mem)

## 20.5 Memory resources [[mem.res]](mem.res#global)

### 20.5.4 Access to program-wide memory_resource objects [mem.res.global]

[ð](#lib:new_delete_resource)

`memory_resource* new_delete_resource() noexcept;
`

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8009)

*Returns*: A pointer to a static-duration object of a type derived from memory_resource that can serve as a resource for allocating memory
using ​::​operator new and ​::​operator delete[.](#1.sentence-1)

The same value is returned every time this function is called[.](#1.sentence-2)

For a return value p and a memory resource r,p->is_equal(r) returns &r == p[.](#1.sentence-3)

[ð](#lib:null_memory_resource)

`memory_resource* null_memory_resource() noexcept;
`

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8025)

*Returns*: A pointer to a static-duration object of a type derived from memory_resource for which allocate() always throws bad_alloc and
for which deallocate() has no effect[.](#2.sentence-1)

The same value is returned every time this function is called[.](#2.sentence-2)

For a return value p and a memory resource r,p->is_equal(r) returns &r == p[.](#2.sentence-3)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8035)

The [*default memory resource pointer*](#def:default_memory_resource_pointer "20.5.4 Access to program-wide memory_­resource objects [mem.res.global]") is a pointer to a memory resource
that is used by certain facilities when an explicit memory resource
is not supplied through the interface[.](#3.sentence-1)

Its initial value is the return value of new_delete_resource()[.](#3.sentence-2)

[ð](#lib:set_default_resource)

`memory_resource* set_default_resource(memory_resource* r) noexcept;
`

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8047)

*Effects*: If r is non-null,
sets the value of the default memory resource pointer to r,
otherwise sets the default memory resource pointer to new_delete_resource()[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8053)

*Returns*: The previous value of the default memory resource pointer[.](#5.sentence-1)

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8057)

*Remarks*: Calling the set_default_resource andget_default_resource functions shall not incur a data race ([[intro.races]](intro.races "6.10.2.2 Data races"))[.](#6.sentence-1)

A call to the set_default_resource function
synchronizes with subsequent calls to
the set_default_resource and get_default_resource functions[.](#6.sentence-2)

[ð](#lib:get_default_resource)

`memory_resource* get_default_resource() noexcept;
`

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/memory.tex#L8072)

*Returns*: The current value of the default memory resource pointer[.](#7.sentence-1)
