Skip to content

PgInternal

Namespace: Ankus

Assembly: Ankus.Runtime.dll

Carries PostgreSQL internal state as an owned managed value or a borrowed native pointer.

public sealed class PgInternal

SQL NULL is represented by a null wrapper. A present value can contain a zero native word. Managed state is rooted until its PostgreSQL owner resets or is deleted. Native pointers retain their original ownership; passing one does not copy or extend its pointee’s lifetime.

Inheritance: object

Wraps a present internal datum, recovering managed ownership when it belongs to this extension.

public PgInternal(PgDatum datum)

Parameters:

datum — PgDatum

A live, non-null PostgreSQL internal value.

Roots a managed value under a PostgreSQL owner and arranges its eventual cleanup.

public static PgInternal Create<T>(T value, PgMemoryContext? context = null) where T : notnull

Type parameters:

T

The exact managed value type.

Parameters:

value — T

The non-null value to retain; IDisposable is called once at owner cleanup.

context — PgMemoryContext

The storage owner, or the current callback’s result owner when omitted.

Returns: PgInternal

The present internal state.

Use mutable classes for state updated across callbacks. An explicit owner controls longer lifetimes. The native address is an opaque identity and does not point to the managed object’s representation.

Borrows a native pointee with an explicit unmanaged representation and checked context lifetime.

[NativeUnsafeAccess]
public PgNativeReference<T>? DangerousBorrow<T>() where T : unmanaged

Type parameters:

T

The caller-proven native representation.

Returns: PgNativeReference<T>

The borrowed reference, or null for a zero pointer.

The caller guarantees at least sizeof(T) initialized, accessible bytes with the correct layout. This method rejects managed state, whose opaque identity is not a native value representation.

Borrows a native internal word under an explicit lifetime anchor without acquiring ownership.

[NativeUnsafeAccess]
public static PgInternal DangerousCreate(nuint bits, PgMemoryContext context)

Parameters:

bits — nuint

The PostgreSQL internal word, including a present zero pointer.

context — PgMemoryContext

The lifetime anchor, which must not outlive the pointed-to storage.

Returns: PgInternal

The borrowed internal value.

The caller guarantees pointer validity and its representation. No earlier native free is detected.

Returns the native word after checking its owner and backend thread.

public nuint DangerousGetBits()

Returns: nuint

The opaque managed identity or borrowed native word.

Reads managed state after checking its exact type, owner, and backend thread.

public T Get<T>() where T : notnull

Type parameters:

T

The exact type supplied to Create.

Returns: T

The retained value. Value types are returned by value.

Gets the raw datum and its checked lifetime without copying the pointed-to state.

public PgDatum Datum { get; }

Value: PgDatum

Gets whether this wrapper refers to managed state created by this extension.

public bool IsManaged { get; }

Value: bool