adafruit / Adafruit_Seesaw

Arduino library driver for seesaw multi-use chip
93 stars 64 forks source link

Unknown RAM consumption source #45

Closed yoann-dufresne closed 3 years ago

yoann-dufresne commented 3 years ago

Hi there,

I'm working on a alt ctrl game using 6 independant NeoTrellis keyboards. In this project I'm using an arduino nano with 2KB of SRAM.

After a few days I raised multiple segfaults due to collisions between stack and heap. I optimized my code and now around 500B of RAM are available (still not enought for some usages).

I had a look at the NeoTrellis lib and I found a strange behaviour when I'm initializing neotrellis The following code using the freeMemory function from here https://learn.adafruit.com/memories-of-an-arduino/measuring-free-memory:

    for (int i=0 ; i<6 ; i++) {
      Serial.print("Before NeoTrellis init ");Serial.println(freeMemory());delay(10);
      this->trellis = new Adafruit_NeoTrellis(addrs[i]);
      Serial.print("After NeoTrellis init ");Serial.println(freeMemory());Serial.println();delay(10);
    }

is producing the following output:

    Before NeoTrellis init 2295
    After NeoTrellis init 1269
    Before NeoTrellis init 1203
    After NeoTrellis init 1130
    Before NeoTrellis init 1064
    After NeoTrellis init 991
    Before NeoTrellis init 925
    After NeoTrellis init 852
    Before NeoTrellis init 786
    After NeoTrellis init 713
    Before NeoTrellis init 647
    After NeoTrellis init 574

As you can see there is a huge RAM consumption when I created the first object (around 1KB) but small ones for the other objects (~75B). I tried to find the source of the 1KB consumption but I'm in a dead end for now.

Do you have any idea of what causes this huge memory allocation ?

In case you need it, my full code is here (init in the class def cube.cpp): https://github.com/yoann-dufresne/project-3 And here is a picture of the controler (for curious people :) ): https://photos.app.goo.gl/YSnD6Wnm1GGsG3nm8

ladyada commented 3 years ago

that isnt unusual, there can be RAM shared between the objects due to the underlying i2c connection. you will need to upgrade to a larger processor!