VirtualMemory class
Owns one region of reserved address space (mmap).
On this page
- Use
import ThinkMeta.ConcurrentTasks.Posix.VirtualMemory;- Namespace
ThinkMeta::ConcurrentTasks::Posix- Platforms
- Linux
Syntax
class VirtualMemoryRemarks
The region is unmapped on destruction. Only the owner calls Reserve and Release, from one thread at a time; the static members act on any address and are as thread-safe as the system calls they wrap. Locking, protection and queries, which Windows::VirtualMemory also has, are not here yet. A commit or decommit of part of a region splits its mapping, and Linux limits the mappings of a process (vm.max_map_count, 65530 by default): commit contiguous windows, as the library's users do, rather than scattered pages.
See also
Constructors
VirtualMemory
~VirtualMemory
Methods
IsValid
Returns whether the object owns a region.
Syntax
bool IsValid() const noexcept;Return value
Type: bool
true if a region is owned; otherwise false.
GetAllocationBase
Returns the start of the region, or nullptr.
Syntax
void* GetAllocationBase() noexcept;Return value
Type: void*
The region's base address; nullptr if the object owns no region.
AtOffset
Returns the address offset bytes into the region.
Syntax
void* AtOffset(std::size_t offset) noexcept;Parameters
offsetstd::size_t- Distance in bytes from the start of the region; must lie inside it.
Return value
Type: void*
The region's base address plus offset.
Remarks
No bounds check.
Reserve
Reserves address space.
Syntax
ErrorCode Reserve(std::size_t size) noexcept;Parameters
sizestd::size_t- Bytes to reserve; rounded up to whole pages.
Return value
Type: ErrorCode
Error::Success (0) on success; otherwise the errno of mmap.
Remarks
Releases the current region, if any, first. Pages must be committed (Commit) before they are touched.
See also
Release
Releases the whole region (munmap).
Syntax
ErrorCode Release() noexcept;Return value
Type: ErrorCode
Error::Success (0) on success, also if there was nothing to release; otherwise the errno of munmap.
Remarks
The object owns nothing afterwards, even if munmap failed.
See also
Commit
Commits pages for reading and writing.
Syntax
static ErrorCode Commit(void* address, std::size_t size) noexcept;Parameters
addressvoid*- Start of the range; rounded down to a page boundary.
sizestd::size_t- Length of the range in bytes; every page it touches is committed.
Return value
Type: ErrorCode
Error::Success (0) on success; otherwise the errno of mprotect.
Remarks
The range must lie inside a reservation. Pages read as zero until written, also after a Decommit.
See also
Decommit
Decommits pages.
Syntax
static ErrorCode Decommit(void* address, std::size_t size) noexcept;Parameters
addressvoid*- Start of the range; rounded down to a page boundary.
sizestd::size_t- Length of the range in bytes; every page it touches is decommitted.
Return value
Type: ErrorCode
Error::Success (0) on success; otherwise the errno of madvise or mprotect.
Remarks
The address range stays reserved; its contents are gone.
See also
Generated from ThinkMeta.ConcurrentTasks.API @ da816bc (2026-11-06).