Table of Contents

Class RawMimeMemoryBudget

Namespace
MailFathom.Application.EmailContent.Storage
Assembly
MailFathom.Application.dll

Bounds how many raw MIME bytes every concurrent work unit of the process may hold in memory at once.

public sealed class RawMimeMemoryBudget
Inheritance
RawMimeMemoryBudget
Inherited Members

Remarks

A payload is buffered whole between the fetch that reads it and the commit that stores it, so peak memory is one payload per work unit in flight. The per-email size limit bounds one of those and says nothing about their sum, which means the peak would otherwise scale with the configured account and folder concurrency: raising a concurrency bound would silently raise the memory ceiling with it. This is the one budget that spans work units, so it is a single process-wide instance rather than a per-run value.

Reservations are granted in request order, and a request is granted only once every earlier one has been. That is what keeps a large message from being starved by a stream of small ones, and it is why the capacity must be at least the per-email size limit: a reservation larger than the whole budget could never be granted, and the work unit asking for it would wait forever. The host validates that at startup, and this type refuses such a request outright rather than waiting on it.

The budget bounds what MailFathom deliberately holds rather than what the runtime has allocated. A reservation is the caller's statement that it is about to hold that many bytes, so it is taken before the fetch and released only once nothing references the payload any more.

Constructors

RawMimeMemoryBudget(long)

Initializes a budget over a fixed number of bytes.

Properties

AvailableBytes

Gets how many bytes of the budget nothing currently holds.

CapacityBytes

Gets the greatest number of raw MIME bytes every work unit together may hold.

Methods

ReserveAsync(long, CancellationToken)

Reserves room for one payload, waiting until the budget has it.