Table of Contents

Class PortableMemorySchema

Namespace
CStructSharp.Memory
Assembly
CStructSharp.dll

Converts a compiled fixed-size Portable layout into a MemorySchema, using the offsets the compiler already computed.

public static class PortableMemorySchema
Inheritance
PortableMemorySchema
Inherited Members

Remarks

When your own CStruct declaration is the authority for a record's layout, there is no metadata to import: the compiled layout already knows every size, offset, pointer width, and codec. This adapter reads those facts through the layout's public introspection and emits equivalent descriptors, so the memory APIs (unsigned addresses, mappings, explicit pointer resolution) become available for records that were declared in the Portable language. The declaration is not parsed again, and no host ABI is consulted.

Only fixed layouts can be projected. A memory schema must know every size up front, so conditional and runtime-sized members are rejected with an explanation; such layouts are read through a finite region's stream view with the ordinary core API instead. Compilation options that affect codecs (custom codecs, long width, enum storage, bitfield allocation) are carried across so the projected scalars decode identically.

Recursive types such as struct Node { Node *next; } are handled by reserving a type's identity before its members are imported, so a pointer back to the type finds an existing ID rather than recursing forever.

Methods

Create(CStruct, string)

Projects a fixed exported root type and every type it references into a new schema.

public static MemorySchema Create(CStruct layout, string rootType)

Parameters

layout CStruct

Compiled Portable layout to project.

rootType string

Name of the fixed-size exported type to start from.

Returns

MemorySchema

A validated schema whose type IDs are the layout's own type names.

Remarks

The returned schema can be reused across sources and sessions. Sizes and offsets come from the layout's introspection only; the adapter never uses Marshal.SizeOf or the host pointer width to fill a gap, and a member without a fixed extent is a reason to reject the projection rather than to substitute zero. Runtime counts and data-sized arrays need a caller-selected finite region and the core stream API.

Exceptions

ArgumentNullException

layout or rootType is null.

ArgumentException

rootType is empty or whitespace.

CStructLayoutException

The root is not a known type, or a reachable type has no memory projection: it is runtime-sized, has a conditional member or a @count pointer, or nests beyond the depth limit.