1
0
forked from Alepha/Alepha

Start moving towards the alignment solution>

Some of this needs to be branched out.
This commit is contained in:
2024-05-20 19:00:37 -04:00
parent 7577caf47b
commit ff738b9301
3 changed files with 13 additions and 7 deletions

View File

@ -221,11 +221,17 @@ namespace Alepha::Hydrogen ::detail:: Blob_m
* inside a large single physical backing. This helps maintain zero-copy semantics.
*
* @param amount The amount of data to carve off.
* @return A new `Blob` object referring to the same physical data, scoped to `amount` bytes.
* @param alignment The size alignment that the new base should be at (the extra padding is
* considered part of the resulting `Blob`).
* @return A new `Blob` object referring to the same physical data, scoped to `amount` bytes (with
* possible extra space, due to alignment).
*/
Blob
carveHead( const std::size_t amount )
carveHead( const std::size_t unalignedAmount, Alignment alignment= Alignment{ 1 } )
{
assert( std::popcount( alignment.amt ) == 1 );
// TODO: Consider arithmetic overflow, here.
const std::size_t amount= alignTo( ( reinterpret_cast< std::uintptr_t >( data() ) % alignment.amt ) + unalignedAmount, alignment );
if( amount > size() ) throw DataCarveTooLargeError( data(), amount, size() );
if( not storage )
{