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

More allocated bytes than necessary #10024

xtonik opened this issue Dec 3, 2022 · 0 comments

More allocated bytes than necessary #10024

xtonik opened this issue Dec 3, 2022 · 0 comments


Copy link

xtonik commented Dec 3, 2022

There is allocated more memory than used for encoding strings in base64.

The implementation always produces base64 strings aligned to four bytes plus one zero terminating character, but number of bytes allocated is higher - see attached encoded_lengths.csv.

It is possible of course, that no memory is saved due to alignment to several bytes blocks for CPU optimization - for alignment to 8 bytes blocks is current implementation correct, but as it is platform dependent, this could not be true in every cases.

Proposed solution:
Replace expression insize * 4 / 3 + 4 with (insize + 2) / 3 * 4 + 1 at line referenced above.

@bagder bagder self-assigned this Dec 3, 2022
bagder added a commit that referenced this issue Dec 3, 2022
The previous algorith allocated more bytes than necessary.

Suggested-by: xtonik on github
Fixes #10024
@bagder bagder closed this as completed in fa467a2 Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Successfully merging a pull request may close this issue.

2 participants