From 15c7d93ea9d36f63260cce74fcd3b695b0b06724 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Sat, 25 Jan 2020 23:50:57 +0100 Subject: 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. --- testdata/gc.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'testdata/gc.go') 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:] } -- cgit v1.2.3