dhiltonp/hexbright

print_binary.cpp is linked/included unintentionally and bloats program

Opened this issue · 3 comments

Anytime ANY file in hb_utilities is referenced the entire folder gets compiled and linked. The linker is pretty good about throwing out what isn't used but I think because eventSerial is referenced in the main.cpp (internal to Arduino) that somehow the Serial stuff sticks in a bad way.

My code:

#include <click_counter.h>

Building:

Global variables use 195 bytes (19%) of dynamic memory,

With that line commented:

Global variables use 22 bytes (2%) of dynamic memory,

Note, I'm not even actually using any click_counter code in this example... the whole difference you are seeing is the extra Serial variable space that's getting added.

I'm not sure of anyway to fix this without putting each of the libraries into separate folders instead of having them all in the same folder. At the very least print_binary should be split off. I can do this and submit a pull request I just wasn't sure what direction I should go with fixing this. Or maybe you have a better idea?

I'm using Arduino 1.5.x but I'd guess the older IDE might exhibit the same behavior.

This memory issue is something I've not seen, as I only see memory usage at run time via DEBUG_* (using Serial).

I'd expect the problem to occurs with 1.0.5 as well, as I'd be surprised if Arduino 1.5 is using a significantly newer version of avr-gcc on the backend.

Simply moving all hb_utilities that use Serial to a separate directory would fix it (this is a bit of a kludge).

My first thought was to slap #ifdef DEBUG around the calls but then I saw the only place that file is used is by one of the test programs... could we just say that serial only works in debug mode and require the test program to define DEBUG?

That would be great, but I think you'll hit a little issue with the #defines... it's the same cause for the BUILD_HACK.

Please try it; maybe you'll see a solution I've missed :).