XO1401: allocation in a real-time function
A function declared uses realtime (core 6.5) may not allocate: list, map, and set literals, string interpolation, + and += on Str, List, or Bytes, slicing, closures, storing into a Map, and every prelude method that builds a new collection or Str or grows one (push, put, insert, sort, map, …). Allocate during initialization instead (in code that is not real-time), and write preallocated Lists by index: xs[i] = v is in place when the List is unique. The message of fault(...) is exempt, since a fault ends the real-time section. Native builds also count allocations at run time and fault with XO-F007 when a section allocated (a shared List copied on write). See decision 0133.
Example
fn tick(var st: State, x: Float) uses realtime {
st.history.push(x)
}Fix
fn tick(var st: State, x: Float) uses realtime {
st.history[st.pos] = x
st.pos = (st.pos + 1) % st.history.len()
}Run xo explain XO1401 for this text in a terminal, or see
section 10.6 of the specification.