mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 06:23:39 +00:00
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:
committed by
Ron Evans
parent
5282b4efac
commit
a4cbe3326e
@@ -37,6 +37,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const gcDebug = false
|
const gcDebug = false
|
||||||
|
const needsStaticHeap = true
|
||||||
|
|
||||||
// Some globals + constants for the entire GC.
|
// Some globals + constants for the entire GC.
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const needsStaticHeap = false
|
||||||
|
|
||||||
// initHeap is called when the heap is first initialized at program start.
|
// initHeap is called when the heap is first initialized at program start.
|
||||||
func initHeap()
|
func initHeap()
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const needsStaticHeap = true
|
||||||
|
|
||||||
// Ever-incrementing pointer: no memory is freed.
|
// Ever-incrementing pointer: no memory is freed.
|
||||||
var heapptr uintptr
|
var heapptr uintptr
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import (
|
|||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const needsStaticHeap = false
|
||||||
|
|
||||||
var gcTotalAlloc uint64 // for runtime.MemStats
|
var gcTotalAlloc uint64 // for runtime.MemStats
|
||||||
var gcMallocs uint64
|
var gcMallocs uint64
|
||||||
var gcFrees uint64
|
var gcFrees uint64
|
||||||
|
|||||||
@@ -79,7 +79,10 @@ var stackTop uintptr
|
|||||||
//
|
//
|
||||||
//export main
|
//export main
|
||||||
func main(argc int32, argv *unsafe.Pointer) int {
|
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.
|
// Store argc and argv for later use.
|
||||||
main_argc = argc
|
main_argc = argc
|
||||||
@@ -298,7 +301,7 @@ var heapMaxSize uintptr
|
|||||||
|
|
||||||
var heapStart, heapEnd uintptr
|
var heapStart, heapEnd uintptr
|
||||||
|
|
||||||
func preinit() {
|
func allocateHeap() {
|
||||||
// Allocate a large chunk of virtual memory. Because it is virtual, it won't
|
// 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
|
// really be allocated in RAM. Memory will only be allocated when it is
|
||||||
// first touched.
|
// first touched.
|
||||||
|
|||||||
Reference in New Issue
Block a user