PgVarlena<T>
Namespace: Ankus
Assembly: Ankus.Runtime.dll
Holds a native-layout PostgreSQL value with checked borrowing and copy-on-write ownership.
public sealed class PgVarlena<T> : IDisposable where T : unmanagedType parameters:
T
A statically registered PgType with NativeLayout enabled.
Direct scalar inputs borrow until their callback exits. A detoasted temporary is writable but still expires with that callback. The first write to borrowed storage creates a private native allocation in the captured source context. Explicit clones use their selected context lifetime. Access requires the originating backend thread and a live native owner. No managed reference to expiring native storage escapes through Value. Dispose owns no PostgreSQL input buffer.
Inheritance: object
Implements: IDisposable
Constructors
Section titled “Constructors”PgVarlena(PgMemoryContext?)
Section titled “PgVarlena(PgMemoryContext?)”Creates a zero-initialized native varlena in the selected context.
public PgVarlena(PgMemoryContext? context = null)Parameters:
context — PgMemoryContext
The owner, or the current context when omitted.
PgVarlena(T, PgMemoryContext?)
Section titled “PgVarlena(T, PgMemoryContext?)”Creates an independent native varlena containing the supplied value.
public PgVarlena(T value, PgMemoryContext? context = null)Parameters:
value — T
The complete native payload.
context — PgMemoryContext
The owner, or the current context when omitted.
Methods
Section titled “Methods”Clone(PgMemoryContext?)
Section titled “Clone(PgMemoryContext?)”Copies this value into independent native storage.
public PgVarlena<T> Clone(PgMemoryContext? destination = null)Parameters:
destination — PgMemoryContext
The destination context, or this value’s captured source context.
Returns: PgVarlena<T>
An independently disposable value.
Dispose()
Section titled “Dispose()”Releases independently owned storage or invalidates an input view without freeing PostgreSQL’s input buffer.
public void Dispose()Failed native release preserves ownership for retry. PostgreSQL context cleanup remains responsible for forgotten handles; no finalizer calls the backend.
IntoDatum()
Section titled “IntoDatum()”Transfers owned storage to a checked datum and consumes this wrapper after success.
public PgDatum IntoDatum()Returns: PgDatum
The datum, valid until its native context resets or is deleted.
Callback inputs, including writable detoast temporaries, are copied before transfer. Failure preserves this wrapper’s original ownership. Normal function returns and SPI bindings copy their payload and do not implicitly consume a wrapper shared by managed aliases.
Properties
Section titled “Properties”Context
Section titled “Context”Gets the checked storage context. A borrowed input also requires its callback lease to remain active.
public PgMemoryContext Context { get; }Value: PgMemoryContext
IsBorrowed
Section titled “IsBorrowed”Gets whether the next write requires a private copy of PostgreSQL’s input.
public bool IsBorrowed { get; }Value: bool
False includes writable detoast temporaries, which remain callback-scoped until explicitly copied.
Gets a copied value or replaces the complete native payload, copying borrowed storage before writing.
public T Value { get; set; }Value: T