Closed
Description
So we have StaticArray
now, which is great on its own but still a managed object, and it would be even greater if there'd also be a way to get some raw static memory. Proposing the following:
Extend the memory
namespace to be also a function, that one can use like
const myMem = memory(64);
yielding a static pointer to 64 bytes of reserved static memory. When using this in a function
function foo(): i32 {
const ptr = memory(4);
var value = load<i32>(ptr);
store<i32>(ptr, value + 1);
return value;
}
the segment will always be exactly the same, so calling the function above multiple times would yield 0, 1, 2, 3, ... quite similar to what static
in C does. This can then be used for various things, like as an alternative to (temporary) stack allocation as long as one makes sure that it is not being accessed in parallel. The argument must be a compile-time constant.
Thoughts?