# `QuakeC.Memory`
[🔗](https://github.com/jaman/cauldron/blob/v0.2.2/quake_c/lib/quake_c/memory.ex#L1)

A QuakeC program's words: a value per index from 0. A word never written is `0`. Values
are floats, integers from `-2^49` up to but not including `2^49`, and binaries.

    memory = QuakeC.Memory.from_list([1.0, 2.0])
    memory = QuakeC.Memory.set(memory, 70_000, 3.0)
    QuakeC.Memory.get(memory, 70_000)
    #=> 3.0

The memory is written in place and every copy of it sees every write, whichever copy
made it: the words are held in `:atomics` chunks of 65536 words, and the chunks and
the binaries in an ETS table. `set/3` and `put/3` may return a memory that reaches a new
chunk without a table lookup; an older copy reaches it through the table.

The table belongs to the process that made the memory: the memory works from any
process while that process lives, and `delete/1` frees it sooner. `copy/1` makes a
memory written apart from the original.

`get_code/2` gives the same read as quoted code, for compiled programs to inline.

# `t`

```elixir
@type t() :: %QuakeC.Memory{chunks: tuple(), table: :ets.tid()}
```

# `copy`

```elixir
@spec copy(t()) :: t()
```

A memory holding the same values whose words are written apart from `memory`'s.

# `delete`

```elixir
@spec delete(t()) :: :ok
```

Free the memory's table; neither it nor any copy of it may be used after.

# `fill`

```elixir
@spec fill(t(), non_neg_integer(), non_neg_integer(), number()) :: t()
```

Write integer or float `value` into `count` words from `index`; the memory to use from then on.

# `from_list`

```elixir
@spec from_list([term()]) :: t()
```

Memory holding `values` from index 0.

# `get`

```elixir
@spec get(t(), non_neg_integer()) :: term()
```

The word at `index`.

# `get_code`

```elixir
@spec get_code(Macro.t(), Macro.t()) :: Macro.t()
```

Code reading word `index` of `memory`, both quoted.

# `move`

```elixir
@spec move(t(), non_neg_integer(), t(), non_neg_integer(), non_neg_integer()) :: t()
```

Copy `count` words of `source` from index `from` into `target` from index `to`, as they
stood before the copy (the ranges may overlap, and `source` may be `target`); the target
memory to use from then on.

# `new`

```elixir
@spec new() :: t()
```

Memory with no words written.

# `put`

```elixir
@spec put(t(), non_neg_integer(), term()) :: :ok | t()
```

Write `value` at `index`: `:ok`, or a memory that reaches the chunk the word is in when
the write made it.

# `set`

```elixir
@spec set(t(), non_neg_integer(), term()) :: t()
```

Write `value` at `index`; the memory to use from then on.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
