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

Why need extra 5 bytes for buf? #255

Open
ruozhiertong opened this issue Apr 9, 2018 · 4 comments
Open

Why need extra 5 bytes for buf? #255

ruozhiertong opened this issue Apr 9, 2018 · 4 comments
Labels

Comments

@ruozhiertong
Copy link

in test.c line 56:/* the extra 5 bytes are because of inaccuracies when reserving memory */
why the the extra 5 bytes ? It is like a magic number.
what reason cause inaccuracies when reserving memory?

@FSMaxB FSMaxB added the question label Apr 9, 2018
@FSMaxB
Copy link
Collaborator

FSMaxB commented Apr 9, 2018

Good question, I should have documented this better back when I did it. The commit that changed this comment was made in pull request #146, before that it was more than that, because back then it wasn't possible to know beforehand, how much space was needed for numbers. Now that numbers are first parsed into a buffer and then copied over, this problem doesn't exist anymore, therefore the change to 5.

But I have to investigate further, where the 5 comes from, I think it had something to do with UTF-16 \uXXXX notation or surrogate pairs.

@FSMaxB
Copy link
Collaborator

FSMaxB commented Apr 9, 2018

I currently can't find any reason why. Needs some more investigation, maybe I can drop these + 5, I think they could have been just "to be safe".

@FSMaxB
Copy link
Collaborator

FSMaxB commented Apr 22, 2018

It definitely was "just to be safe". I haven't had the time yet to review all the codepaths thoroughly enough to ensure that the required memory isn't still overestimated (by a smaller margin) somewhere.

@huang4115
Copy link

I seem to have found the reason for the inaccurate memory estimate. Please take a look at #283

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

No branches or pull requests

3 participants