Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lower memory usage #192

Merged
merged 1 commit into from
Jun 13, 2024
Merged

Lower memory usage #192

merged 1 commit into from
Jun 13, 2024

Conversation

mathieucarbou
Copy link
Contributor

No description provided.

@ayushsharma82
Copy link
Owner

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
Copy link
Contributor Author

mathieucarbou commented Jun 10, 2024

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.

@ayushsharma82 ayushsharma82 merged commit b451846 into ayushsharma82:dev Jun 13, 2024
11 checks passed
@mathieucarbou mathieucarbou deleted the memory branch June 27, 2024 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants