libcaramel
caramel::memory_resource Class Referenceabstract

Abstract class defining the interface of a memory resource. More...

#include <memory_resource.hpp>

Inheritance diagram for caramel::memory_resource:
caramel::global_resource

Public Types

using pointer = void *
 alias for ease of naming
 
using const_pointer = const void *
 alias for ease of naming
 

Public Member Functions

 memory_resource (const memory_resource &) noexcept=default
 
 memory_resource (memory_resource &&) noexcept=default
 
auto operator= (const memory_resource &) noexcept -> memory_resource &=default
 
auto operator= (memory_resource &&) noexcept -> memory_resource &=default
 
auto operator== (const memory_resource &rhs) const -> bool
 Check if two memory_resources are equal. More...
 
virtual auto allocate (count_t bytes, align_t alignment) noexcept -> pointer=0
 Pure virtual function for a common allocation interface. More...
 
virtual void deallocate (gsl::not_null< pointer > ptr, count_t bytes, align_t alignment) noexcept=0
 Pure virtual function for a common deallocation interface. More...
 
virtual auto is_equal (const memory_resource &other) const noexcept -> bool=0
 Pure virtual function for a common comparison interface. More...
 

Detailed Description

Abstract class defining the interface of a memory resource.

Member Function Documentation

◆ allocate()

virtual auto caramel::memory_resource::allocate ( count_t  bytes,
align_t  alignment 
) -> pointer
pure virtualnoexcept

Pure virtual function for a common allocation interface.

Precondition
bytes >= 0, otherwise UB
alignment >= 0, otherwise UB
Parameters
[in]bytesThe size of the allocation in bytes
[in]alignmentThe alignment of the allocation in bytes
Returns
A valid pointer to a memory chunk or nullptr if the allocation failed

Implemented in caramel::global_resource.

◆ deallocate()

virtual void caramel::memory_resource::deallocate ( gsl::not_null< pointer ptr,
count_t  bytes,
align_t  alignment 
)
pure virtualnoexcept

Pure virtual function for a common deallocation interface.

Precondition
bytes >= 0, otherwise UB
alignment >= 0, otherwise UB
Parameters
[in]ptrThe starting location of the memory chunk
[in]bytesThe size of the allocation in bytes
[in]alignmentThe alignment of the allocation in bytes

Implemented in caramel::global_resource.

◆ is_equal()

virtual auto caramel::memory_resource::is_equal ( const memory_resource other) const -> bool
pure virtualnoexcept

Pure virtual function for a common comparison interface.

Parameters
[in]otherThe memory_resource to compare with.
Returns
True if both memory_resources are considered equal, otherwise false

Implemented in caramel::global_resource.

◆ operator==()

auto caramel::memory_resource::operator== ( const memory_resource rhs) const -> bool

Check if two memory_resources are equal.

Use the virtual is_equal function to compare if two memory_resources are equal like so: this == &rhs or is_equal(rhs).

Parameters
[in]other
Returns

The documentation for this class was generated from the following files: