aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/gc.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2020-01-25 23:50:57 +0100
committerRon Evans <[email protected]>2020-01-27 19:01:55 +0100
commit15c7d93ea9d36f63260cce74fcd3b695b0b06724 (patch)
tree0f02d1c487208a4f2bef37b5349453721fe18541 /testdata/gc.go
parent6e26728391a7cc73f8c7a4a1587898bbf6887529 (diff)
downloadtinygo-15c7d93ea9d36f63260cce74fcd3b695b0b06724.tar.gz
tinygo-15c7d93ea9d36f63260cce74fcd3b695b0b06724.zip
avr: use a garbage collector
This might sound crazy, but I think it's better to enable the GC by default to avoid surprises. It costs 1130 bytes of flash and 16 bytes of RAM (plus heap overhead) so it's not exactly free, but if needed it can easily be disabled with `-gc=leaking`. On the Uno (32kB flash, 2kB RAM) that's not massive, on the DigiSpark (8kB flash, 0.5kB RAM) that may be too much depending on the application.
Diffstat (limited to 'testdata/gc.go')
-rw-r--r--testdata/gc.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/testdata/gc.go b/testdata/gc.go
index b9a1ba475..eb594db6c 100644
--- a/testdata/gc.go
+++ b/testdata/gc.go
@@ -23,6 +23,13 @@ var scalarSlices [4][]byte
var randSeeds [4]uint32
func testNonPointerHeap() {
+ maxSliceSize := uint32(1024)
+ if ^uintptr(0) <= 0xffff {
+ // 16-bit and lower devices, such as AVR.
+ // Heap size is a real issue there, while it is still useful to run
+ // these tests. Therefore, lower the max slice size.
+ maxSliceSize = 64
+ }
// Allocate roughly 0.5MB of memory.
for i := 0; i < 1000; i++ {
// Pick a random index that the optimizer can't predict.
@@ -38,9 +45,9 @@ func testNonPointerHeap() {
}
// Allocate a randomly-sized slice, randomly sliced to be smaller.
- sliceLen := randuint32() % 1024
+ sliceLen := randuint32() % maxSliceSize
slice := make([]byte, sliceLen)
- cutLen := randuint32() % 1024
+ cutLen := randuint32() % maxSliceSize
if cutLen < sliceLen {
slice = slice[cutLen:]
}