#include <alignable.h>
Protected Member Functions | |
constexpr StatusWithSize | DoCanAlloc (Layout layout) const |
Static Protected Member Functions | |
static constexpr BlockResult< Derived > | DoAllocFirst (Derived *&&block, Layout layout) |
static constexpr BlockResult< Derived > | DoAllocLast (Derived *&&block, Layout layout) |
Friends | |
template<typename > | |
class | BlockWithLayout |
Mix-in for blocks that can be split on alignment boundaries.
Block mix-ins are stateless and trivially constructible. See BasicBlock
for details on how mix-ins can be combined to implement blocks.
This mix-in requires its derived type also derive from AllocatableBlock
.
|
staticconstexprprotected |
Splits an aligned block from the start of the block, and marks it as used.
If successful, block
will be replaced by a block that has an inner size of at least inner_size
, and whose starting address is aligned to an alignment
boundary. If unsuccessful, block
will be unmodified.
This method is static in order to consume the given block pointer. On success, a pointer to the new, smaller block is returned. In total, up to two additional blocks may be created: one to pad the returned block to an alignment boundary and one for the trailing space. On error, the original pointer is returned.
For larger alignments, the AllocLast
method is generally preferable to this method, as this method may create an additional fragments both before and after the returned block in order to align the usable space.
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The split completed successfully. The `BlockAllocType` indicates * how extra memory was distributed to other blocks. * * FAILED_PRECONDITION: This block is in use and cannot be split. * * RESOURCE_EXHAUSTED: The available space is insufficient to fulfill the * request. This may be due to a large requested size, or insufficient * remaining space to fulfill the requested alignment create a valid * leading block, and/or create a valid trailing block. * *
|
staticconstexprprotected |
Splits an aligned block from the end of the block, and marks it as used.
If successful, block
will be replaced by a block that has an inner size of at least inner_size
, and whose starting address is aligned to an alignment
boundary. If unsuccessful, block
will be unmodified.
This method is static in order to consume the given block pointer. On success, a pointer to the new, smaller block is returned. In total, up to two additional blocks may be created: one to pad the returned block to an alignment boundary and one for the trailing space. On error, the original pointer is returned.
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: The split completed successfully. The `BlockAllocType` indicates * how extra memory was distributed to other blocks. * * FAILED_PRECONDITION: This block is in use and cannot be split. * * RESOURCE_EXHAUSTED: The available space is insufficient to fulfill the * request. This may be due to a large requested size, or insufficient * remaining space to fulfill the requested alignment create a valid * leading block, and/or create a valid trailing block. * *
|
constexprprotected |
Checks if a block could be split from the block.
On error, this method will return the same status as AllocFirst
or AllocLast
without performing any modifications.
embed:rst:leading-asterisk * * .. pw-status-codes:: * * OK: Returns the number of bytes to shift this block in order to align * its usable space. * * FAILED_PRECONDITION: This block is in use and cannot be split. * * RESOURCE_EXHAUSTED: The available space is insufficient to fulfill the * request. This may be due to a large requested size, or insufficient * remaining space to fulfill the requested alignment create a valid * leading block, and/or create a valid trailing block. * *