# Memory membrane

> How the SEG models all memory as one value, why that makes aliasing and out-of-bounds effects visible, and how pointers and arrays lower.

Source: https://atracode.com/docs/memory-membrane

Inside a [Semantic Execution Graph](/docs/semantic-execution-graph), all memory is a single value called the membrane. The membrane is threaded through the graph from one memory operation to the next. Every read takes the membrane as an input. Every write takes the membrane in and produces a new one.

Nothing in the graph can touch memory any other way. That one rule is what lets Atracode lower pointer-heavy code exactly and show you every effect it has.

## Reads and writes are edges

In most compilers, memory is a side channel: a store happens, and later loads may or may not see it depending on what else aliased the same address. In a SEG, the order and dependencies of memory operations are part of the graph itself.

Take a short C function that swaps two values through pointers:

```c
void swap(int *a, int *b) {
    int t = *a;
    *a = *b;
    *b = t;
}
```

Lowered, this becomes a chain on the membrane:

```text
m0                      membrane in
t  = read(m0, a)        32-bit read at a
u  = read(m0, b)        32-bit read at b
m1 = write(m0, a, u)    new membrane with *a = u
m2 = write(m1, b, t)    new membrane with *b = t
m2                      membrane out
```

The second write takes `m1`, the membrane produced by the first write. If `a` and `b` point to the same address, the graph still describes exactly what happens, because the dependency is explicit. Nothing depends on the compiler guessing whether the two pointers alias.

## What this makes visible

Because every access is an edge, effects that are normally hidden become things you can inspect:

- **Aliasing.** Two pointers that refer to the same memory produce reads and writes on the same membrane chain. Whether a write is seen by a later read follows from the graph's structure.
- **Out-of-bounds effects.** An access through a pointer or index is an explicit operation with an explicit address and width. A write past the end of an array is in the graph where you can see it; it can't quietly change some unrelated value.
- **What a function really touches.** `atracode inspect` lists a SEG's membrane reads and writes alongside its inputs and bounds. If a function you expected to be read-only writes memory, it shows up there.

This is also why the [security page](/security) describes every memory access as visible: a tampered build that added a hidden write would produce a different graph, and a different [RAVEN hash](/docs/raven).

## How C pointers and arrays lower

C is the language that leans on memory most directly, and Atracode lowers its full model through the membrane: pointers, pointer arithmetic, arrays, structs, unions, function pointers, variadics and exact two's-complement wrapping. The result runs with no libc and no operating system.

In general terms:

| Source construct | In the SEG |
| --- | --- |
| `*p` (load) | A read on the membrane at `p`, with the exact width of the pointed-to type |
| `*p = v` (store) | A write that produces a new membrane |
| `p + n` | Address arithmetic scaled by the element size, as the C standard defines it |
| `a[i]` | A read or write at the array's base plus `i` elements |
| Struct and union fields | Reads and writes at fixed offsets from the base, so a union's overlapping fields share the same bytes |
| Parameters written through a pointer | Writes on the membrane that the caller sees after the call |

C++ follows the same model for classes, `std::array`, `std::vector` and range-for with write-back. Other systems languages (Rust, Zig, Go, Odin) lower their slices, structs and pointer or reference parameters the same way, with each language's own integer-width and wrapping rules.

Languages without raw pointers still use the membrane. Java and C# arrays, Pascal `var` parameters, VB.NET `ByRef` arguments and COBOL working storage all become membrane reads and writes, which is how write-back through parameters keeps its exact meaning.

Some languages also have membranes for I/O. A PowerShell script reads and writes files through an explicit file-system membrane, so its effects on files are as visible as a C program's effects on memory.

## Next steps

- [Semantic Execution Graph](/docs/semantic-execution-graph): the graph the membrane runs through
- [Verification](/docs/verification): how output and memory are checked against the native toolchain
- [Languages](/docs/languages): what each language lowers and what it is verified against
