mike-matera / ArduinoSTL

An STL and iostream implementation based on uClibc++ that supports my CS-11M class.
GNU General Public License v3.0
323 stars 80 forks source link

cout should support const char arrays from flash #43

Open pischky opened 5 years ago

pischky commented 5 years ago

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 commented 5 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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

chrisco484 commented 2 years ago

@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 commented 2 years ago

Hello,

I have created a Pull Request. Did not know that you can edit online on github without local git installation. See #69 Thanks for your library.

Martin

Am 04.01.2022 um 01:45 schrieb Christopher Colemani:

@chrisco484 <https://github.com/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 https://github.com/pischky 's patch zip to a PR.

— Reply to this email directly, view it on GitHub https://github.com/mike-matera/ArduinoSTL/issues/43#issuecomment-1004451799, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADTXTRQKDJNGE6KWIUCS3LDUUI7LVANCNFSM4I3ZWR7Q. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

--

Martin Pischky, Oisseler Strasse 1C, 30559 Hannover, Germany http://www.pischky.de @.*** tel: +49 511 7000665 mobile: +49 151 11592222

Ebola-Chan-bot commented 3 days ago

See my fork that supports this.