Layout
public struct Layout { /* private fields */ }Size + alignment pair describing the memory footprint of a type.
Allocators take a Layout rather than a raw byte count so they can
honour alignment requirements (SIMD types, page-aligned buffers, etc.).
The static of[T] and array[T] factories cover the common cases;
merge and padToAlign exist for hand-rolled struct layouts.
Examples
let l = Layout.of[Int64](); // size 8, alignment 8
let buf = Layout.array[UInt8](1024); // size 1024, alignment 1
allocator.allocate(l)
Representation
Two Int64s — size and alignment. No invariants enforced at
construction; misaligned layouts are caught (or undefined) at the
allocator level.
Properties
public var alignment: Int64
public var alignment: Int64Required alignment in bytes — always a power of two for layouts
produced by of/array.
public var size: Int64
public var size: Int64Footprint in bytes.
Initializers
public init(size: Int64, alignment: Int64)
public init(size: Int64, alignment: Int64)Builds a layout from explicit size and alignment. Caller is
responsible for keeping alignment a power of two.
Methods
public static func array[T](Int64) -> Layout
public static func array[T](Int64) -> LayoutLayout for count contiguous T values. Inherits the element's
alignment; size is sizeof[T] * count with no inter-element padding
(T is assumed already padded to its own alignment).
public func merge(with: Layout) -> (Layout, Int64)
public func merge(with: Layout) -> (Layout, Int64)Concatenates other after self, mimicking how a C struct lays
out its second field. Returns the combined layout and the byte
offset where other's storage starts (handy for building field
access tables by hand).
public static func of[T]() -> Layout where T: not Copyable
public static func of[T]() -> Layout where T: not CopyableLayout for a single value of T — uses the compiler-known
sizeof and alignof for the type.
public func padToAlign() -> Layout
public func padToAlign() -> LayoutRounds size up to the next multiple of alignment. Use when
emitting a value into a packed array — without padding, element
i+1 would land at the wrong offset.
ImplementsEquatable
Associated Types
type Output = Bool
type Output = BoolMethods
public func equal(to: Self) -> Bool
public func equal(to: Self) -> BoolBridges Equal.equal(to:) to Equatable.isEqual(to:).
public func isEqual(to: Layout) -> Bool
public func isEqual(to: Layout) -> BoolEqual when both fields match.
public func notEqual(to: Self) -> Bool
public func notEqual(to: Self) -> BoolDefault !=: delegates to == so there's a single source of truth.
Defined in lang/std/memory/layout.ks