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

printf_buffered(), buffering for putchar_ #104

Closed
kjsdf7wr3 opened this issue Jan 25, 2022 · 1 comment
Closed

printf_buffered(), buffering for putchar_ #104

kjsdf7wr3 opened this issue Jan 25, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@kjsdf7wr3
Copy link

printf from <stdio.h> provides buffering via some other internal functions.
It would be nice, if this repo offered a printf variant, which operates on a user provided buffer to reduce the calls to putchar_.

Example:

void puts_(const char * data, int length)
{
    // handle data block wise, instead of char wise like in putchar_
}

char buffer[10];
printf_buffered(buffer, sizeof(buffer), "0123456789+2");  // <-- calls puts_(buffer, 10); puts(buffer+10, 2);
printf_buffered(buffer, sizeof(buffer), "abc");          // <-- calls puts_(buffer, 3); 

Of course, one could also implement this kind of buffering inside putchar_, but at least if built without LTO, the performance would be quite a bit better for the printf_buffered.

@eyalroz eyalroz added the enhancement New feature or request label Jan 25, 2022
@eyalroz
Copy link
Owner

eyalroz commented Jan 25, 2022

This library's scope will not expand to also cover stream buffering. While it is certainly useful to have - if you want this...

  • You can achieve this using fctprintf() - simply use a function which applies such buffering.
  • Write a library depending on libprintf, which utilizes either fctprintf(), or sprintf_() into its buffer, to implement printf_buffered().

@eyalroz eyalroz closed this as completed Jan 25, 2022
kuba2k2 pushed a commit to libretiny-eu/library-printf that referenced this issue Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants