Use F-macro for flash-strings, conserves SRAM #157
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
---------------------------- DO NOT DELETE OR EDIT anything above this line ----------------------------
Hey there! Thanks for using the SPIFlash library for Arduino.
Please note that starting 01.03.2018 any Pull request raised here MUST be submitted according to this template or it will be flagged with 'Not enough information'. No action will be taken till all the prerequisite information is provided. If no information is provided for over a month, the pull request will be closed.
Pull request details
Use the F() macro to load strings from "flash" (program memory) instead of having them
all initialized in SRAM
Serial.print("String"); all over the place
On worst case scenario all of those strings are statically allocated and initialized in SRAM on boot
I have not checked how the compiler handles allocation of strings in methods on different platforms but would expect it's all static.
Serial.print(F("String"));
This macro stores the string in program memory from where it's read one byte at a time when used,
conserving SRAM (there is of course clock-cycle overhead involved but it's small and one would not be printing strings to the serial port if one needed to squeeze the last bit of performance out of the mcu anyway).
I have not tested this on every "Arduino compatible" platform but I would expect the macro to be
no-op where the platform does not support (or need) the functionality. I've tested this on Teensy3.2 and it does work (haven't actually compared the compiler details on statically allocated RAM so not sure if it actually does anything on the ARM Cortex-M4)