mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 18:47:47 +00:00
00e91ec569
dumb -> leaking: make it more clear what this "GC" does: leak everything. marksweep -> conservative: "marksweep" is too generic, use "conservative" to differentiate between future garbage collectors: precise marksweep / mark-compact / refcounting.
48 lines
1.0 KiB
Go
48 lines
1.0 KiB
Go
// +build gc.leaking
|
|
|
|
package runtime
|
|
|
|
// This GC implementation is the simplest useful memory allocator possible: it
|
|
// only allocates memory and never frees it. For some constrained systems, it
|
|
// may be the only memory allocator possible.
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
// Ever-incrementing pointer: no memory is freed.
|
|
var heapptr = heapStart
|
|
|
|
func alloc(size uintptr) unsafe.Pointer {
|
|
// TODO: this can be optimized by not casting between pointers and ints so
|
|
// much. And by using platform-native data types (e.g. *uint8 for 8-bit
|
|
// systems).
|
|
size = align(size)
|
|
addr := heapptr
|
|
heapptr += size
|
|
if heapptr >= heapEnd {
|
|
runtimePanic("out of memory")
|
|
}
|
|
for i := uintptr(0); i < uintptr(size); i += 4 {
|
|
ptr := (*uint32)(unsafe.Pointer(addr + i))
|
|
*ptr = 0
|
|
}
|
|
return unsafe.Pointer(addr)
|
|
}
|
|
|
|
func free(ptr unsafe.Pointer) {
|
|
// Memory is never freed.
|
|
}
|
|
|
|
func GC() {
|
|
// No-op.
|
|
}
|
|
|
|
func KeepAlive(x interface{}) {
|
|
// Unimplemented. Only required with SetFinalizer().
|
|
}
|
|
|
|
func SetFinalizer(obj interface{}, finalizer interface{}) {
|
|
// Unimplemented.
|
|
}
|