Home / Docs / Configure a package

[run] max_memory

What it does

A running program holds memory for its values: lists, maps, text. una run stops a run that holds more than its memory budget, 4096 MiB unless told otherwise, and reports where. max_memory declares the package's own budget, in MiB, so every run of it has the same limit: una run, una test and the executable una build makes.

In edition 0.3 it is a key of [run] in una.toml:

una.tomltoml
[package]
name = "meter"
version = "0.1.0"
edition = "0.3"

[run]
entry = "meter"
grants = ["console"]
max_memory = 64
src/meter.unauna
module meter

pub main() -> Unit
  uses @console: Console[print]
=
  @console.print("ready")

From edition 0.4 it is a line of run in ita.una, after entry:

ita.unauna
ita meter
  version 0.1.0
  edition 0.4

run
  entry meter
  max_memory 64
  grants
    console
src/meter.unauna
module meter

pub main() -> Unit
  uses @console: Console[print]
=
  @console.print("ready")

Forms

toml
[run]
max_memory = <MiB>               -- una.toml, edition 0.3

run
  max_memory <MiB>               -- ita.una, edition 0.4

An integer from 1 to 4096.

Examples

A budget outside that range is rejected:

una.tomltoml
[package]
name = "meter"
version = "0.1.0"
edition = "0.3"

[run]
entry = "meter"
grants = ["console"]
max_memory = 0
src/meter.unauna
-- fails with U7002
module meter

pub main() -> Unit
  uses @console: Console[print]
=
  @console.print("ready")

The same in ita.una is U7008 at the value:

ita.unauna
-- fails with U7008
ita meter
  version 0.1.0
  edition 0.4

run
  entry meter
  max_memory 8192
  grants
    console
src/meter.unauna
module meter

pub main() -> Unit
  uses @console: Console[print]
=
  @console.print("ready")

Edge cases

The flag may lower the budget, never raise it. With max_memory = 64, --max-memory 32 runs with 32 MiB, and --max-memory 128 stops with a usage error, exit code 2, before the program starts: --max-memory 128 is above the package's declared max_memory of 64 MiB; it may lower the budget, never raise it. The same holds for una test and for the built executable, which carries the budget in its embedded description.

Further rules:

Diagnostics

Edition

max_memory exists from edition 0.3, which is a preview, as a key of una.toml, and in edition 0.4, also a preview, as a line of ita.una. In editions 0.1 and 0.2 it is an unknown key.

Normative source