runtime: only allocate heap memory when needed

For example, with -gc=none and -gc=leaking, no heap needs to be
allocated when initializing the runtime. And some GCs (like -gc=custom)
are responsible for allocating the heap themselves.
This commit is contained in:
Ayke van Laethem
2024-08-05 16:12:48 +02:00
committed by Ron Evans
parent 5282b4efac
commit a4cbe3326e
5 changed files with 12 additions and 2 deletions
+5 -2
View File
@@ -79,7 +79,10 @@ var stackTop uintptr
//
//export main
func main(argc int32, argv *unsafe.Pointer) int {
preinit()
if needsStaticHeap {
// Allocate area for the heap if the GC needs it.
allocateHeap()
}
// Store argc and argv for later use.
main_argc = argc
@@ -298,7 +301,7 @@ var heapMaxSize uintptr
var heapStart, heapEnd uintptr
func preinit() {
func allocateHeap() {
// Allocate a large chunk of virtual memory. Because it is virtual, it won't
// really be allocated in RAM. Memory will only be allocated when it is
// first touched.