[mem.res.private]

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

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

### 20.5.2 Class memory_resource [[mem.res.class]](mem.res.class#mem.res.private)

#### 20.5.2.3 Private virtual member functions [mem.res.private]

[ð](#lib:do_allocate,memory_resource)

`virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
`

[1](#1)

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

*Preconditions*: alignment is a power of two[.](#1.sentence-1)

[2](#2)

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

*Returns*: A derived class shall implement this function to
return a pointer to allocated storage ([[basic.stc.dynamic.allocation]](basic.stc.dynamic.allocation "6.8.6.5.2 Allocation functions"))
with a size of at least bytes,
aligned to the specified alignment[.](#2.sentence-1)

[3](#3)

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

*Throws*: A derived class implementation shall throw an appropriate exception if it is unable to allocate memory with the requested size and alignment[.](#3.sentence-1)

[ð](#lib:do_deallocate,memory_resource)

`virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
`

[4](#4)

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

*Preconditions*: p was returned from a prior call to allocate(bytes, alignment) on a memory resource equal to *this,
and the storage at p has not yet been deallocated[.](#4.sentence-1)

[5](#5)

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

*Effects*: A derived class shall implement this function to dispose of allocated storage[.](#5.sentence-1)

[6](#6)

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

*Throws*: Nothing[.](#6.sentence-1)

[ð](#lib:do_is_equal,memory_resource)

`virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
`

[7](#7)

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

*Returns*: A derived class shall implement this function to return true if memory allocated from *this can be deallocated from other and vice-versa,
otherwise false[.](#7.sentence-1)

[*Note [1](#note-1)*:

It is possible that the most-derived type of other does not match the type of *this[.](#7.sentence-2)

For a derived class D, an implementation of this function
can immediately return false if dynamic_cast<const D*>(&other) == nullptr[.](#7.sentence-3)

â *end note*]
