Skip to content

Struct Layout and Cache Line Inspector

github-actions[bot] edited this page Nov 30, 2026 · 1 revision

Struct Layout, Cache-Line Inspector, and Typed Memory Overlays

Compiler alignment rules can silently bloat C and C++ data structures with hidden padding bytes, and a single hot scalar straddling a 64-byte L1 cache-line boundary can trigger false sharing across OpenMP worker threads. GridLock pairs a built-in DWARF struct layout and cache-line analyzer with live typed memory overlays so you can spot wasted padding, eliminate cache-line splits, and inspect raw heap buffers using real struct field names and values.

Struct Layout and 64-Byte Cache-Line Inspector analyzing HaloParticle


Inspect a Struct Layout and 64-Byte Cache Lines

Why use it: Find compiler alignment holes, fields crossing 64-byte cache-line boundaries, and how many bytes you can reclaim by reordering struct members.

  1. Load your ELF target compiled with DWARF debug symbols (-g or -g -O0) from the main toolbar or build your workspace (Tools -> Build Target).
  2. Open Tools -> Struct Layout & Cache-Line Inspector... (or open Search Everywhere with Ctrl+Shift+P and choose Struct Layout & Cache-Line Inspector...).
  3. Enter a C or C++ struct or class name in Struct / Class: (for example, HaloParticle or Particle) and click Inspect (or press Enter).
  4. Review the summary banner across the top of the window:
    • Total byte size (sizeof), natural alignment (align), total padding bytes, and wasted byte percentage.
    • Total 64-byte cache lines spanned and whether multiple writable fields or split fields trigger a FALSE-SHARING RISK warning.
  5. Scan the byte-map table row by row:
    • Cache-Line Dividers (Cache Line 0 [0..63], Cache Line 1 [64..127]): Mark every 64-byte boundary cleanly.
    • Padding Holes (/* XXX N-byte hole */, /* XXX N-byte tail padding */): Highlight amber alignment gaps inserted by the compiler.
    • Bitfields (+offset:bit) and Virtual Table Pointers (vptr): Show exact bit offsets/widths and hidden C++ vptr slots.
    • Straddle Warnings (L0 -> L1): Flag any member whose byte span crosses a 64-byte cache-line boundary.
  6. Check Greedy Optimal Packed Layout Preview: at the bottom of the dialog to copy a member-reordering suggestion showing the compacted size and bytes saved.

Overlay Struct Fields Directly on Hex Memory ((StructType*)0x...)

Why use it: Replace raw hexadecimal bytes in Memory View with decoded field names, types, live values, and padding holes in one step.

Memory View displaying a live typed (Particle*)0x00404000 overlay alongside hex and ASCII rows

  1. Open the Memory View tab under Debug in the bottom tool rail and select HEX DUMP.
  2. In the Addr: box, type a C-style typed pointer cast around a target hex address or expression, for example:
    (Particle*)0x00404000
    
    Modifiers such as const and struct (for example, (const struct HaloParticle *)0x7fff1234) are accepted automatically.
  3. Click Read (or press Enter). GridLock reads memory at that address, resolves the struct's DWARF layout from the active binary, and displays a TYPED OVERLAY summary banner at the top of the hex dump.
  4. Read decoded field annotations (tag(uint8_t)=42, energy(double)=128.75) and alignment holes (/* XXX 7-byte hole */) inline beside each matching 16-byte hex/ASCII row.
  5. To return to an untyped hex dump, replace the Addr: expression with a plain hex address (such as 0x00404000) or register/symbol ($rsp) and click Read.

Reference

Capability Details
Menu & Palette Entry Tools -> Struct Layout & Cache-Line Inspector... / Search Everywhere > Struct Layout & Cache-Line Inspector...
Cache-Line Width Fixed 64-byte hardware cache-line boundaries (Line 0 [0..63], Line 1 [64..127], ...)
Supported Field Types Scalars (bool, signed/unsigned 8/16/32/64-bit ints, float, double), pointers, vptr slots, fixed arrays, bitfields (offset:bit, width)
Typed Cast Grammar (TypeName*)0xHEX, (struct TypeName *)0xHEX, (const TypeName*)0xHEX inside Memory View -> Addr:

For related low-level workflows (hex diffing across MPI ranks, virtual memory treemaps, Pointer Graph, and 2D Control Flow Graphs), see Memory, Reverse Engineering, and Profiling.

Clone this wiki locally