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

cout should support const char arrays from flash #43

Open
pischky opened this issue Sep 30, 2019 · 6 comments
Open

cout should support const char arrays from flash #43

pischky opened this issue Sep 30, 2019 · 6 comments

Comments

@pischky
Copy link

pischky commented Sep 30, 2019

It should be possible to use Macro "F()" to store strings (const char*) from flash memory (PROGMEM) like Arduinio print/println does. This saves RAM.

cout << F("\r\nSystem halted!") << endl;

The Arduino library uses class __FlashStringHelper in macro F(). I have added (in "ostream")

template<class charT, class traits> _UCXXEXPORT basic_ostream<charT,traits>&
    operator<<(basic_ostream<charT,traits>& out, const __FlashStringHelper* c)

and

template<class traits> _UCXXEXPORT basic_ostream<char,traits>&
    operator<<(basic_ostream<char,traits>& out, const __FlashStringHelper* c)

With code from Arduino library file Print.cpp. Have given it a short test and it works on Arduino UNO with current IDE / eclipse.

Will try to attach patch.

@pischky
Copy link
Author

pischky commented Sep 30, 2019

ostream.patch.zip

This zip contains patch file and complete changed file "ostream". Feel free to remove "[PI: New]"

BTW: Thanks for this library. Makes life much easer ;-)

@chrisco484
Copy link

ostream.patch.zip

This zip contains patch file and complete changed file "ostream". Feel free to remove "[PI: New]"

BTW: Thanks for this library. Makes life much easer ;-)

Thanks! This is exactly what I needed as my free mem on a 328P got very low and the code was using AduinoSTL with lots of

cout << "blah" << endl;

@chrisco484
Copy link

ostream.patch.zip

This zip contains patch file and complete changed file "ostream". Feel free to remove "[PI: New]"

BTW: Thanks for this library. Makes life much easer ;-)

I've just tested this patch and it works brilliantly. I've been able to save a lot of precious RAM on a few "third drawer" Uno borads I have lying around.

Have you raised a PR for this patch? A PR it will be more likely to be merged into master.

@mike-matera
Copy link
Owner

@chrisco484 Would you send me this as a PR? I'd be happy to take it.

@chrisco484
Copy link

@chrisco484 Would you send me this as a PR? I'd be happy to take it.

Hi Mike,

I ended up hitting too many resource constraints with 328P based boards so moved up to STM32 blue pills/black pills with ARM Cortex CPUs - wow! So much faster and so much more resources and actually cheaper and they still support the Arduino "APIs" so all my Arduino software targeting the 328Ps just recompiled with very little change required. So it was a no brainer.

I'll try to find some time to convert @pischky 's patch zip to a PR.

@pischky
Copy link
Author

pischky commented Jan 4, 2022 via email

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

No branches or pull requests

3 participants