Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Development
  3. Using the F macro in the presentation function

Using the F macro in the presentation function

Scheduled Pinned Locked Moved Development
6 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • alowhumA Offline
    alowhumA Offline
    alowhum
    Plugin Developer
    wrote on last edited by alowhum
    #1

    Since version 2.2 it has become possible to use the F( ) macro in a few more places. For example this would give an error in 2.1:

    void presentation()
    {
      sendSketchInfo(F("SMS receiver"), F("1.6"));
    }
    

    Arduino's compiler says this saves a bit of memory. Does it? Or is all the memory returned anyway once the presentation function is done?

    If not, then it would rock if it also becomes possible to use the macro in the present lines. This currently gives an error:

      present(SMS_CHILD_ID, S_INFO, F("received sms"));
    

    Before I make a feature request I thought I'd ask here if this would actually save memory or not.

    mfalkviddM 1 Reply Last reply
    0
    • alowhumA alowhum

      Since version 2.2 it has become possible to use the F( ) macro in a few more places. For example this would give an error in 2.1:

      void presentation()
      {
        sendSketchInfo(F("SMS receiver"), F("1.6"));
      }
      

      Arduino's compiler says this saves a bit of memory. Does it? Or is all the memory returned anyway once the presentation function is done?

      If not, then it would rock if it also becomes possible to use the macro in the present lines. This currently gives an error:

        present(SMS_CHILD_ID, S_INFO, F("received sms"));
      

      Before I make a feature request I thought I'd ask here if this would actually save memory or not.

      mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      @alowhum yes it saves ram (but not flash, to be clear - the term memory is often used for flash as well)

      When a sketch is executed on the microcontroller, all variables are normally loaded into ram, "locking" them there. The F macro prevents this, and only loads the text to ram temporarily when needed.

      More information: https://www.arduino.cc/reference/en/language/variables/utilities/progmem/

      1 Reply Last reply
      0
      • alowhumA Offline
        alowhumA Offline
        alowhum
        Plugin Developer
        wrote on last edited by
        #3

        @mfalkvidd thanks, I understand that. That's why I like using F( ) as much as possible, to save ram.

        That's why I would like to use it on the child descriptions too.

        But I suspected that the creators of MySensors to have already thought about this problem, and that I was just missing the obvious because of my limited knowledge. All I could think up though, was that the ram used by the child description strings is released.

        But I also remember how people don't like strings. And as far as I understand these child descriptions would be turned into strings at runtime? So they could (still) have a memory fragmenting effect?

        mfalkviddM 1 Reply Last reply
        0
        • alowhumA alowhum

          @mfalkvidd thanks, I understand that. That's why I like using F( ) as much as possible, to save ram.

          That's why I would like to use it on the child descriptions too.

          But I suspected that the creators of MySensors to have already thought about this problem, and that I was just missing the obvious because of my limited knowledge. All I could think up though, was that the ram used by the child description strings is released.

          But I also remember how people don't like strings. And as far as I understand these child descriptions would be turned into strings at runtime? So they could (still) have a memory fragmenting effect?

          mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by mfalkvidd
          #4

          @alowhum when using the F macro, I think the (temporary) ram for the string will be allocated on the stack, so there will be no fragmentation. When not using the F macro, the string will be placed permanently in ram, so there will be no fragmentation.

          It could be that using the F macro for presentation causes problems inside the library, but it could also be as simple as nobody thought of adding support (or had enough time/energy to do it).

          1 Reply Last reply
          0
          • alowhumA Offline
            alowhumA Offline
            alowhum
            Plugin Developer
            wrote on last edited by alowhum
            #5

            I thought the F( ) macro told Arduino to not load the variable into ram permanently? That it would just re-load it from the flash whenever it needed it?

            mfalkviddM 1 Reply Last reply
            0
            • alowhumA alowhum

              I thought the F( ) macro told Arduino to not load the variable into ram permanently? That it would just re-load it from the flash whenever it needed it?

              mfalkviddM Offline
              mfalkviddM Offline
              mfalkvidd
              Mod
              wrote on last edited by
              #6

              @alowhum yes that is correct

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              13

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular