Skip to content

memoryLayoutOf

memoryLayoutOf<T>(schema, accessor?): PrimitiveOffsetInfo

A function that retrieves offset and information for a specific primitive within a data schema. Example usage:

const Boid = d.struct({
position: d.vec3f,
velocity: d.vec3f,
});
const memLayout = d.memoryLayoutOf(Boid, (b) => b.velocity.y);
console.log(memLayout.offset); // Byte offset of velocity.y within Boid (here 20 bytes)
console.log(memLayout.contiguous); // Contiguous bytes available from that offset (here 8 bytes)

T extends BaseData

T

The data schema to analyze.

(proxy) => number

Optional function that accesses a specific primitive within the schema. If omitted, uses the root offset (0).

PrimitiveOffsetInfo

An object containing the offset and contiguous byte information.

packages/typegpu/src/data/offsetUtils.ts:324