Int size in flash mem, relative to a byte, seems to be 210 bytes?

Hi! I’m making an LED lantern project using Arduino via PlatformIO / C++, built on an ATtiny84.

My core issue is that I’m running out of space on the MCU.

My main current issue is that, while trying to compress filesize, I’ve found that my int s seem to be taking up WAY more than the 2 bytes they’re supposed to. Specifically, I’ve found one that seems to be taking up 208 bytes , which is… uh, more, than two. Even if there were some funky behind-the-scenes assignment of pointers and stuff, there’s NO way changing a single int to a byte should save this much space?

I’m concerned because, while I AM converting as many ints to bytes as I can, there are several I have to keep as ints for tracking larger values. Not to mention the libraries I’m using, where there’s probably many ints in use. If every int is taking up ~210 bytes, that’s a HUGE issue when I only have 8kB of flash.

Any idea what’s going on here? And, hopefully, how to prevent it?


Pics of the issue showing the code and terminal output below (imgur album). Note that the result seems the same whether I use static or not, int8_t / int16_t instead of byte / int , whatever.

The project is open source, so if you want to look at the code in its entirety, here you go.

I’ve also made a post on Reddit about this issue, and there’s been some discussion there. No solutions or explanations yet, though :confused:


Thank you!



Showing the filesize using an int (7524 bytes)



Showing the filesize using a byte (7316 bytes, 208 fewer)



Showing the filesize using a byte (7316 bytes, 208 fewer)

Don’t you think that your variable is located in RAM? The difference between 240 and 237 fits perfectly the difference between int and byte :wink:

I think the most upvoted comment in that reddit thread already has the solution.

set LOOP_INTERVAL_SLEEP=1000 and a byte can only count up to 255 - which causes the entire body of your loopSleep function
sleep.cpp:27:28: warning: comparison is always false due to limited range of data type [-Wtype-limits]
27 | if (_loopIntervalSleep >= LOOP_INTERVAL_SLEEP)