github.com/aykevl/tinygo@v0.5.0/src/runtime/gc_dumb.go (about)

     1  // +build gc.dumb
     2  
     3  package runtime
     4  
     5  // This GC implementation is the simplest useful memory allocator possible: it
     6  // only allocates memory and never frees it. For some constrained systems, it
     7  // may be the only memory allocator possible.
     8  
     9  import (
    10  	"unsafe"
    11  )
    12  
    13  // Ever-incrementing pointer: no memory is freed.
    14  var heapptr = heapStart
    15  
    16  func alloc(size uintptr) unsafe.Pointer {
    17  	// TODO: this can be optimized by not casting between pointers and ints so
    18  	// much. And by using platform-native data types (e.g. *uint8 for 8-bit
    19  	// systems).
    20  	size = align(size)
    21  	addr := heapptr
    22  	heapptr += size
    23  	if heapptr >= heapEnd {
    24  		runtimePanic("out of memory")
    25  	}
    26  	for i := uintptr(0); i < uintptr(size); i += 4 {
    27  		ptr := (*uint32)(unsafe.Pointer(addr + i))
    28  		*ptr = 0
    29  	}
    30  	return unsafe.Pointer(addr)
    31  }
    32  
    33  func free(ptr unsafe.Pointer) {
    34  	// Memory is never freed.
    35  }
    36  
    37  func GC() {
    38  	// No-op.
    39  }
    40  
    41  func KeepAlive(x interface{}) {
    42  	// Unimplemented. Only required with SetFinalizer().
    43  }
    44  
    45  func SetFinalizer(obj interface{}, finalizer interface{}) {
    46  	// Unimplemented.
    47  }