pub struct Region { /* private fields */ }
Expand description
A region for a suballocator to allocate within. All suballocations will be in bounds of this region.
In order to prevent arithmetic overflow when allocating, the region’s end must not exceed
DeviceLayout::MAX_SIZE
.
The suballocator knowing the offset of the region rather than only the size allows you to easily suballocate suballocations. Otherwise, if regions were always relative, you would have to pick some maximum alignment for a suballocation before suballocating it further, to satisfy alignment requirements. However, you might not even know the maximum alignment requirement. Instead you can feed a suballocator a region that is aligned any which way, and it makes sure that the absolute offset of the suballocation has the requested alignment, meaning the offset that’s already offset by the region’s offset.
There’s one important caveat: if suballocating a suballocation, and the suballocation and the suballocation’s suballocations aren’t both only linear or only nonlinear, then the region must be aligned to the buffer-image granularity. Otherwise, there might be a buffer-image granularity conflict between the parent suballocator’s allocations and the child suballocator’s allocations.
Implementations§
source§impl Region
impl Region
sourcepub const fn new(offset: DeviceSize, size: DeviceSize) -> Option<Self>
pub const fn new(offset: DeviceSize, size: DeviceSize) -> Option<Self>
Creates a new Region
from the given offset
and size
.
Returns None
if the end of the region would exceed DeviceLayout::MAX_SIZE
.
sourcepub const unsafe fn new_unchecked(offset: DeviceSize, size: DeviceSize) -> Self
pub const unsafe fn new_unchecked(offset: DeviceSize, size: DeviceSize) -> Self
Creates a new Region
from the given offset
and size
without doing any checks.
Safety
- The end of the region must not exceed
DeviceLayout::MAX_SIZE
, that is the infinite-precision sum ofoffset
andsize
must not exceed the bound.
sourcepub const fn offset(&self) -> DeviceSize
pub const fn offset(&self) -> DeviceSize
Returns the offset where the region begins.
sourcepub const fn size(&self) -> DeviceSize
pub const fn size(&self) -> DeviceSize
Returns the size of the region.