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-15 22:26:13 -04:00
parent 9bd1772fe2
commit 7070a9364c
3 changed files with 16 additions and 9 deletions

View File

@ -8,9 +8,10 @@ static_assert( __cplusplus > 2020'99 );
#include <memory>
#include <Alepha/swappable.h>
#include <Alepha/Exception.h>
#include "Buffer.h"
#include "swappable.h"
#include "Exception.h"
//#include "threading.h"
#include "error.h"
@ -221,11 +222,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 )
{