TByteRangeStream.ReadAt

Document management, Performance, Concurrency

Description

Reads bytes at an absolute source offset without changing the positional TStream cursor

Concurrent callers share an in-flight fetch for the same aligned chunk, while queued adjacent chunks are fetched together in one bounded source request

Syntax

Delphi

Function TByteRangeStream.ReadAt(Offset: Int64; Var Buffer; Count: LongInt): LongInt;

Parameters

OffsetThe absolute zero-based source offset
BufferThe destination for the returned bytes
CountThe maximum number of bytes to read

Return values

0The offset or count is invalid, the offset is at or beyond the source end, or the source request failed
>0The number of bytes copied to Buffer

Remarks

TByteRangeStream is declared in PDFlibNetPDF and its constructor accepts CoalesceWindowMS, which defaults to 2 milliseconds

The window is applied only to the first uncached chunk of each ReadAt call; subsequent chunks continue immediately, and positional Read calls do not wait for the window

A value of zero disables the initial collection delay while preserving same-chunk single-flight sharing and merging requests already queued behind another source read

One merged source fetch is capped at 16 MiB, and source callbacks are serialized so a callback implementation does not need its own transport lock

Do not call back into the same stream from its source callback, and destroy the stream only after all active readers have completed

ClearCache invalidates the cache generation; callers already waiting still receive their bytes, but stale completions cannot repopulate the cleared cache or counters