Table of Contents

Interface IPixelMemorySource

Namespace
Egami
Assembly
Egami.dll

Supplies the memory behind every PixelPlane<TPixel>. Implement it to control where pixel memory comes from. Implementations must be thread-safe.

public interface IPixelMemorySource

Examples

private sealed class CountingSource(IPixelMemorySource inner) : IPixelMemorySource
{
    public int Blocks;
    public long Bytes;

    public int MaxBlockBytes => inner.MaxBlockBytes;

    public IMemoryOwner<byte> Allocate(int byteLength, ClearMode clear)
    {
        Interlocked.Increment(ref Blocks);
        Interlocked.Add(ref Bytes, byteLength);
        return inner.Allocate(byteLength, clear);   // ClearMode.Zero when the caller needs zeroed memory
    }
}

Properties

MaxBlockBytes

Gets the largest block, in bytes, the source hands out in one piece. Planes bigger than this are split into several blocks, each holding whole rows. A single row larger than this still gets one block of its own.

int MaxBlockBytes { get; }

Property Value

int

Methods

Allocate(int, ClearMode)

Allocates one contiguous block of memory.

IMemoryOwner<byte> Allocate(int byteLength, ClearMode clear)

Parameters

byteLength int

The size of the block in bytes. The returned memory has exactly this length.

clear ClearMode

Whether to zero the block.

Returns

IMemoryOwner<byte>

The block. Disposing it returns the memory to the source.