1// +build gc.leaking
2
3package 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
9import (
10	"unsafe"
11)
12
13// Ever-incrementing pointer: no memory is freed.
14var heapptr = heapStart
15
16func 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
33func free(ptr unsafe.Pointer) {
34	// Memory is never freed.
35}
36
37func GC() {
38	// No-op.
39}
40
41func KeepAlive(x interface{}) {
42	// Unimplemented. Only required with SetFinalizer().
43}
44
45func SetFinalizer(obj interface{}, finalizer interface{}) {
46	// Unimplemented.
47}
48
49func initHeap() {
50	// Nothing to initialize.
51}
52