You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
The text was updated successfully, but these errors were encountered:
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:strlen()
calls we have nowHowever, 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 callreserve((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 overloadedoperator=
to empty the buffer and free the memory (seems this is currently the only way to shrink the memory).The text was updated successfully, but these errors were encountered: