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

Convert string buffers to use String class #79

Closed
matthijskooijman opened this issue Mar 7, 2014 · 0 comments
Closed

Convert string buffers to use String class #79

matthijskooijman opened this issue Mar 7, 2014 · 0 comments

Comments

@matthijskooijman
Copy link
Collaborator

A lot of places now use dynamic buffers using a lot of reallocing. We should replace this by instances of Arduino's String class, because:

  • That simplifies code
  • That keeps an explicit length, saving a lot of strlen() calls we have now
  • Reduces chances of getting memory leaks

However, to do this efficiently, we should first finish billroy/bitlash#31 which makes it easier to let bitlash print to a String (by having a StringStream class for example).

When implementing this, we should consider to use the String::reserve method to allocate memory in blocks instead of reallocing for every single character added (e.g., we should call reserve((new_len + BLOCK_SIZE - 1) % BLOCK_SIZE) before adding to the string.

Furthermore, after we're done with a buffer, we should assign NULL to it buffer = NULL, which will be handled by an overloaded operator= to empty the buffer and free the memory (seems this is currently the only way to shrink the memory).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant