Public Member Functions | List of all members
rmm::mr::detail::block Struct Reference

A simple block structure specifying the size and location of a block of memory, with a flag indicating whether it is the head of a block of memory allocated from the heap (or upstream allocator). More...

#include <coalescing_free_list.hpp>

Inheritance diagram for rmm::mr::detail::block:
Inheritance graph
[legend]
Collaboration diagram for rmm::mr::detail::block:
Collaboration graph
[legend]

Public Member Functions

 block (char *ptr, size_t size, bool is_head)
 
char * pointer () const
 Returns the pointer to the memory represented by this block. More...
 
size_t size () const
 Returns the size of the memory represented by this block. More...
 
bool is_head () const
 Returns whether this block is the start of an allocation from an upstream allocator. More...
 
bool operator< (block const &rhs) const noexcept
 Comparison operator to enable comparing blocks and storing in ordered containers. More...
 
block merge (block const &b) const noexcept
 Coalesce two contiguous blocks into one. More...
 
bool is_contiguous_before (block const &b) const noexcept
 Verifies whether this block can be merged to the beginning of block b. More...
 
bool fits (size_t sz) const noexcept
 Is this block large enough to fit sz bytes? More...
 
bool is_better_fit (size_t sz, block const &b) const noexcept
 Is this block a better fit for sz bytes than block b? More...
 
void print () const
 Print this block. For debugging.
 
- Public Member Functions inherited from rmm::mr::detail::block_base
void * pointer () const
 Returns the raw pointer for this block.
 
bool is_valid () const
 Returns true if this block is valid (non-null), false otherwise.
 
void print () const
 Prints the block to stdout.
 

Additional Inherited Members

- Public Attributes inherited from rmm::mr::detail::block_base
void * ptr {}
 Raw memory pointer.
 

Detailed Description

A simple block structure specifying the size and location of a block of memory, with a flag indicating whether it is the head of a block of memory allocated from the heap (or upstream allocator).

Member Function Documentation

◆ fits()

bool rmm::mr::detail::block::fits ( size_t  sz) const
inlinenoexcept

Is this block large enough to fit sz bytes?

Parameters
szThe size in bytes to check for fit.
Returns
true if this block is at least sz bytes

◆ is_better_fit()

bool rmm::mr::detail::block::is_better_fit ( size_t  sz,
block const &  b 
) const
inlinenoexcept

Is this block a better fit for sz bytes than block b?

Parameters
szThe size in bytes to check for best fit.
bThe other block to check for fit.
Returns
true If this block is a tighter fit for sz bytes than block b.
false If this block does not fit sz bytes or b is a tighter fit.

◆ is_contiguous_before()

bool rmm::mr::detail::block::is_contiguous_before ( block const &  b) const
inlinenoexcept

Verifies whether this block can be merged to the beginning of block b.

Parameters
bThe block to check for contiguity.
Returns
true Returns true if this blocks's ptr + size == b.ptr, and not b.is_head, false otherwise.

◆ is_head()

bool rmm::mr::detail::block::is_head ( ) const
inline

Returns whether this block is the start of an allocation from an upstream allocator.

A block b may not be coalesced with a preceding contiguous block a if b.is_head == true.

Returns
true if this block is the start of an allocation from an upstream allocator.

◆ merge()

block rmm::mr::detail::block::merge ( block const &  b) const
inlinenoexcept

Coalesce two contiguous blocks into one.

this must immediately precede b and both this and b must be from the same upstream allocation. That is, this->is_contiguous_before(b). Otherwise behavior is undefined.

Parameters
bblock to merge
Returns
block The merged block

◆ operator<()

bool rmm::mr::detail::block::operator< ( block const &  rhs) const
inlinenoexcept

Comparison operator to enable comparing blocks and storing in ordered containers.

Orders by ptr address.

Parameters
rhs
Returns
true if this block's ptr is < than rhs block pointer.
false if this block's ptr is >= than rhs block pointer.

◆ pointer()

char* rmm::mr::detail::block::pointer ( ) const
inline

Returns the pointer to the memory represented by this block.

Returns
the pointer to the memory represented by this block.

◆ size()

size_t rmm::mr::detail::block::size ( ) const
inline

Returns the size of the memory represented by this block.

Returns
the size in bytes of the memory represented by this block.

The documentation for this struct was generated from the following file: