Skip to content

Conversation

@klausler
Copy link
Contributor

Decrease memory allocation for buffers, allocate the pseudo-unit only once on demand, and avoid using a "%*.s" format.

Decrease memory allocation for buffers, allocate the pseudo-unit
only once on demand, and avoid using a "%*.s" format.
char save{buffer[bytes]};
mutableBuffer[bytes] = '\0';
std::printf("%s", buffer);
mutableBuffer[bytes] = save;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering why we need to care about this byte?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be a NUL at the end of the string for "%s" formatting to work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is clear to me :) but why do we need to restore the original byte value, if we always allocate an extra byte?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a circular buffer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Thanks!

@klausler klausler merged commit cf4be78 into llvm:main Dec 12, 2025
11 checks passed
@klausler klausler deleted the bug1851 branch December 12, 2025 23:01
anonymouspc pushed a commit to anonymouspc/llvm that referenced this pull request Dec 15, 2025
Decrease memory allocation for buffers, allocate the pseudo-unit only
once on demand, and avoid using a "%*.s" format.
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Dec 19, 2025
Decrease memory allocation for buffers, allocate the pseudo-unit only
once on demand, and avoid using a "%*.s" format.
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Dec 20, 2025
Decrease memory allocation for buffers, allocate the pseudo-unit only
once on demand, and avoid using a "%*.s" format.
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.

3 participants