ayushsharma82 / ElegantOTA

OTA updates made slick and simple for everyone!
https://elegantota.pro
GNU Affero General Public License v3.0
643 stars 119 forks source link

Lower memory usage #192

Closed mathieucarbou closed 5 months ago

ayushsharma82 commented 5 months ago

I guess, I started using char arrays instead of String because - one day I read an article which said String causes heap fragmentation and uses more bytes than it saves for little data.

Don't know if that's true, happy to hear your thoughts on it.

mathieucarbou commented 5 months ago

Well, I frankly prefer having just a few bytes allocated for my stat value, than 64 * 20 bytes for all the stats cards.

String is really helpfull in saving memory if it is used correctly.

One bad usage for example I often see:

void my_function(String foo)

instead of:

void my_function(String& foo)

or....

String a = "ggggg";
while(...) { a += "fff";  }

instead of:

String a;
a.reserve(...);
a += "ggggg";
while(...) { a += "fff";  }

operators have been override in the String class so += in this example won't cause a new memory allocation.