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

Represents a chunk of memory that can be allocated and deallocated. More...

#include <arena.hpp>

Public Member Functions

 block ()=default
 Construct a default block.
 
 block (char *pointer, size_t size)
 Construct a block given a pointer and size. More...
 
 block (void *pointer, size_t size)
 Construct a block given a void pointer and size. More...
 
void * pointer () const
 Returns the underlying pointer.
 
size_t size () const
 Returns the size of the block.
 
bool is_valid () const
 Returns true if this block is valid (non-null), false otherwise.
 
bool is_superblock () const
 Returns true if this block is a superblock, false otherwise.
 
bool is_contiguous_before (block const &b) const
 Verifies whether this block can be merged to the beginning of block b. More...
 
bool fits (std::size_t sz) const
 Is this block large enough to fit sz bytes? More...
 
std::pair< block, blocksplit (std::size_t sz) const
 Split this block into two by the given size. More...
 
block merge (block const &b) const
 Coalesce two contiguous blocks into one. More...
 
bool operator< (block const &b) const
 Used by std::set to compare blocks.
 

Detailed Description

Represents a chunk of memory that can be allocated and deallocated.

A block bigger than a certain size is called a "superblock".

Constructor & Destructor Documentation

◆ block() [1/2]

rmm::mr::detail::arena::block::block ( char *  pointer,
size_t  size 
)
inline

Construct a block given a pointer and size.

Parameters
pointerThe address for the beginning of the block.
sizeThe size of the block.

◆ block() [2/2]

rmm::mr::detail::arena::block::block ( void *  pointer,
size_t  size 
)
inline

Construct a block given a void pointer and size.

Parameters
pointerThe address for the beginning of the block.
sizeThe size of the block.

Member Function Documentation

◆ fits()

bool rmm::mr::detail::arena::block::fits ( std::size_t  sz) const
inline

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_contiguous_before()

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

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 block's pointer + size == b.ptr, and not b.is_head, false otherwise.

◆ merge()

block rmm::mr::detail::arena::block::merge ( block const &  b) const
inline

Coalesce two contiguous blocks into one.

this->is_contiguous_before(b) must be true.

Parameters
bblock to merge.
Returns
block The merged block.

◆ split()

std::pair<block, block> rmm::mr::detail::arena::block::split ( std::size_t  sz) const
inline

Split this block into two by the given size.

Parameters
szThe size in bytes of the first block.
Returns
std::pair<block, block> A pair of blocks split by sz.

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