memory::region class

defines a region of memory that might be physically backed depending on the allocator.

memory regions allow for easy managing of virtual memory in a platform abstract way. it provides some helper utilities to allocate correctly sized segments for the given type and even allows constructor/destructors to be called (using the memory::region::create()/memory::region::destroy() methods). Memory regions do not allocate memory in one go, they reserve and "grow to" the specified size (like how virtual memory behaves). How they do this is platform specific however, but should not be of concern for the end-user.

types

typedefs

template<>
state =
describes the various states memory can be in.
privateprivate

constructors, destructors, conversion operators

region
specialized constructor used for internal usage
private
region
constructs a region of atleast the given size, using the alignment value.
public

member-functions

allocate
tries to allocate a segment of atleast the given size.
public
create_region
creates a sub-region of atleast that size.
public

Function documentation

memory::region::region(region& parent, memory::segment& segment, uint64_t pageSize, uint64_t alignment, allocator_base* allocator = new default_allocator()) private

Brief

specialized constructor used for internal usage

Details

we keep this one private as it relies on certain conditions on the size of the segment (being aligned to pages, and starting at a page).

memory::region::region(uint64_t size, uint64_t alignment, allocator_base* allocator = new default_allocator())

Brief

constructs a region of atleast the given size, using the alignment value.

Details

Parameters
size in the minimum size you wish to create a virtual region for.
alignment in the alignment value of the region.
allocator in the allocator that should be used internally.

std::optional<segment> memory::region::allocate(size_t size)

Brief

tries to allocate a segment of atleast the given size.

Parameters
size in the minimum size of the segment (will be aligned to the alignment rules).
Returns a memory::segment on success.

std::optional<memory::region> memory::region::create_region(size_t size, std::optional<size_t> alignment, allocator_base* allocator = new default_allocator())

Brief

creates a sub-region of atleast that size.

Details

Creates a sub region of atleast the given size. The region could be bigger depending on certain factors such as alignment, etc.. Destruction/cleanup happens automatically through the destructor of the created region.