Implement minimal bump pointer allocator

Useful for MCUs, until a real garbage collector has been implemented.
This commit is contained in:
Ayke van Laethem
2018-06-03 16:18:40 +02:00
parent b45ea2deb9
commit e171f32493
4 changed files with 163 additions and 62 deletions
+16
View File
@@ -3,6 +3,10 @@
package runtime
import (
"unsafe"
)
// #include <stdio.h>
// #include <stdlib.h>
// #include <unistd.h>
@@ -21,3 +25,15 @@ func Sleep(d Duration) {
func abort() {
C.abort()
}
func alloc(size uintptr) unsafe.Pointer {
buf := C.calloc(1, C.size_t(size))
if buf == nil {
panic("cannot allocate memory")
}
return buf
}
func free(ptr unsafe.Pointer) {
C.free(ptr)
}