Skip to content

Static memory segment idea #1232

Closed
@dcodeIO

Description

@dcodeIO

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions