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

Rewrite MicroBitImage parsing code so it doesn't depend on atoi() #325

Merged
merged 1 commit into from
Dec 19, 2017

Conversation

dpgeorge
Copy link
Contributor

Using the function atoi() pulls in a dependency from newlib, which in turn
pulls in locale support, and locale support requires about 350 bytes of
RAM. This patch removes such a dependency by rewriting the MicroBitImage
parsing code so that it directly converts the input string to an integer
instead of building a buffer and passing it to atoi().

This patch saves about 640 bytes of code space and 364 bytes of RAM. It
also reduces the amount of stack space used by the MicroBitImage
constructor.

See #323 for further discussion.

Using the function atoi() pulls in a dependency from newlib, which in turn
pulls in locale support, and locale support requires about 350 bytes of
RAM.  This patch removes such a dependency by rewriting the MicroBitImage
parsing code so that it directly converts the input string to an integer
instead of building a buffer and passing it to atoi().

This patch saves about 640 bytes of code space and 364 bytes of RAM.  It
also reduces the amount of stack space used by the MicroBitImage
constructor.
@dpgeorge
Copy link
Contributor Author

I tested this with the simple-animation code in microbit-samples. It seems to work.

@finneyj
Copy link
Contributor

finneyj commented Dec 19, 2017

Thanks @dpgeorge - looks good, thanks for the contribution.

@finneyj finneyj merged commit 2cff906 into lancaster-university:master Dec 19, 2017
@dpgeorge dpgeorge deleted the image-remove-atoi branch December 19, 2017 21:07
@dpgeorge
Copy link
Contributor Author

Thanks @finneyj!

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