-
Notifications
You must be signed in to change notification settings - Fork 150
Replace SOURCE[] with dynamic array
#186
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
Conversation
| PH2_IR = malloc(MAX_IR_INSTR * sizeof(ph2_ir_t)); | ||
| LABEL_LUT = malloc(MAX_LABEL * sizeof(label_lut_t)); | ||
| SOURCE = malloc(MAX_SOURCE); | ||
| SOURCE = create_source(MAX_SOURCE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of choosing an appropriate power of 2 for MAX_SOURCE. perhaps 2^18 (262144 B, or 256 KiB) or 2^19 (524288 B, or 512 KiB) would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then, we do need scientific ways to calculate.
SOURCE[] with dynamic array
jserv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read https://cbea.ms/git-commit/ carefully and enforce the rules.
Replaces the static string "SOURCE" in "src/global.c" with a dynamically allocated array using malloc and free. - Replaced SOURCE[] with a dynamically allocated array. - Updated related logic accordingly. Co-authored-by: Kyle Lin <[email protected]>
|
Thank @icgmilk for contributing! |
This pull request replace
SOURCE(insrc/global.c) with a dynamically allocated array instead of a static string. This change improves memory flexibility.Changes
malloc/free.Performance Analysis
Before:
/usr/bin/time -v ./out/shecc ./src/main.cAfter:
/usr/bin/time -v ./out/shecc ./src/main.cThe dynamic array version used slightly more memory, likely due to the overhead introduced by dynamic memory allocation.
Summary by Bito
This pull request enhances memory flexibility by replacing the static char* SOURCE with a dynamically allocated array. It introduces a new structure for dynamic arrays and updates the lexer, parser, and inliner for compatibility. While there is a slight increase in memory usage, overall performance has improved for handling varying input sizes.Unit tests added: False
Estimated effort to review (1-5, lower is better): 2