Preliminary. ThinkMeta ConcurrentTasks and this documentation are preliminary; everything is subject to change.

API reference / Memory

SpscVirtualMemoryPipe class

A zero-copy pipe between one producer task and one consumer task.

Use
import ThinkMeta.ConcurrentTasks.Memory.SpscVirtualMemoryPipe;
Namespace
ThinkMeta::ConcurrentTasks::Memory
Inherits
IReadSequentialMemory, IWriteSequentialMemory

Syntax

Remarks

The producer writes through IWriteSequentialMemory, the consumer reads through IReadSequentialMemory; both get pointers into a contiguous virtual address range, so neither side copies. Initialize reserves address space for the whole announced size (rounded up to 64 KiB); the producer must not write more than that. Memory is committed in 64 KiB steps on RequestWriteMemory and decommitted in 64 KiB steps once the consumer has released them, so the committed memory is about the distance between the two sides. The consumer waits (suspends) in GetSize until Initialize and in RequestReadMemory until enough data or the end of the stream has arrived; the producer never waits. Both sides must therefore be tasks (or converted threads). A failure to reserve, commit or decommit memory ends the process. The producer calls Initialize also for an empty stream, since GetSize waits for it.

See also

Windows::VirtualMemory

Constructors

SpscVirtualMemoryPipe

Constructs an empty pipe.

Syntax

SpscVirtualMemoryPipe() noexcept = default;

Remarks

The producer calls Initialize first.

Methods

GetSize

Returns the size announced by Initialize.

Syntax

std::size_t GetSize() const noexcept;

Return value

Type: std::size_t

The announced stream size in bytes.

Remarks

Suspends the caller until Initialize has been called.

RequestReadMemory

Returns the next block of the stream.

Syntax

const std::byte* RequestReadMemory(std::size_t& size) noexcept override;

Parameters

sizestd::size_t&
On entry the wanted number of bytes; at the end of the stream it shrinks to what is left.

Return value

Type: const std::byte*

The block, or nullptr with size 0 once the stream is exhausted.

Remarks

Suspends until the producer has released that many bytes (ReleaseWriteMemory) or has set the end of the stream (SetEndOfStream).

See also

ReleaseReadMemory

ReleaseReadMemory

Releases consumed bytes.

Syntax

void ReleaseReadMemory(std::size_t size) noexcept override;

Parameters

sizestd::size_t
Number of the oldest bytes handed out by RequestReadMemory that are no longer used; 0 is allowed.

Remarks

Whole 64 KiB steps behind the consumer are decommitted.

Initialize

Reserves address space for the stream.

Syntax

void Initialize(std::size_t initialSize) noexcept override;

Parameters

initialSizestd::size_t
Total number of bytes the producer will write; 0 for an empty stream (nothing is reserved).

Remarks

Call once. Releases a consumer waiting in GetSize.

RequestWriteMemory

Returns the next writable block, committing pages as needed.

Syntax

std::byte* RequestWriteMemory(std::size_t size) noexcept override;

Parameters

sizestd::size_t
Number of bytes the block must hold; the total must stay within the size given to Initialize.

Return value

Type: std::byte*

The block; never nullptr.

Remarks

The producer stays within the size announced by Initialize; a failed commit ends the process.

See also

ReleaseWriteMemory

ReleaseWriteMemory

Publishes written bytes to the consumer and wakes it.

Syntax

void ReleaseWriteMemory(std::size_t size) noexcept override;

Parameters

sizestd::size_t
Number of bytes written into the oldest unreleased block; at most its requested size, 0 allowed.

See also

RequestReadMemory

SetEndOfStream

Marks the end of the stream and wakes the consumer.

Syntax

void SetEndOfStream() noexcept override;

Generated from ThinkMeta.ConcurrentTasks.API @ 137ec1d (2026-10-17).