-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Similar to class implementation, you should be able to store variables on STACK rather than HEAP with the static keyword.
Please note that the implementation of static on a class property or method is different from global statics. Method and properties of classes will remain on HEAP.
Example implementation:
import * from std.http;
import JSON from std;
static api_endpoint: string = "https://myapi.com/api/"; // will never change and collected from stack
const version: Future<JSON> = await fetch(api_endpoint);
print("API Version: " + version);It is important to note, if you do not declare a static global as public it is disposed after it is owned. (this can be disabled with compiler flags)
Why? Allocating known strings or any related interface on heap is more time consuming than allocating on stack. Allocating on stack allows us to shorten instruction size into a single instruction, as well as allowing better lifetime control of the variable.
Please note this RFC will not be as efficient without lifetimes enabled