mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 16:33:40 +00:00
runtime: add "end of heap" to detect out of memory
This can be used in the future to trigger garbage collection. For now, it provides a more useful error message in case the heap is completely filled up.
This commit is contained in:
@@ -20,6 +20,9 @@ func alloc(size uintptr) unsafe.Pointer {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user