Adjust the size of cJSON from 64 to 56 through memory alignment#608
Open
yangbodong22011 wants to merge 1 commit intoDaveGamble:masterfrom
Open
Adjust the size of cJSON from 64 to 56 through memory alignment#608yangbodong22011 wants to merge 1 commit intoDaveGamble:masterfrom
yangbodong22011 wants to merge 1 commit intoDaveGamble:masterfrom
Conversation
e90904f to
c3c6a12
Compare
Collaborator
|
hi @yangbodong22011 , thanks your great contribution! This optimization could indeed save memory in some scenarios, but this is a breaking change, users need change the initiation of the cJSON struct, so it may merged in the next major version, such as 1.8 or 2.0 |
By adjusting the position, the valueint and type memory are aligned, occupying a total of 8 bytes instead of 16 bytes, so sizeof(cJSON) is reduced from 64 bytes to 56 bytes. p.s. Although this optimization may not be effective in the memory allocator's view, because the size that the allocator may allocate is 64 bytes, it may be effective in some scenarios, and it will not be worse than the current situation.
c3c6a12 to
79293f5
Compare
Author
|
@Alanscut Thanks for your reply, let's stay open and wait for more comments. |
isodnc
approved these changes
Oct 22, 2021
|
This is an ABI-break, not an API break. All that would be required here is incrementing the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By adjusting the position, the
valueintandtypememory are aligned, occupying a total of 8 bytes
instead of 16 bytes, so sizeof(cJSON) is reduced
from 64 bytes to 56 bytes.
p.s. Although this optimization may not be
effective in the memory allocator's view, because
the size that the allocator may allocate is 64 bytes,
it may be effective in some scenarios, and it will
not be worse than the current situation.
code: