Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • 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
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Other Discussions
  3. The Insider News
  4. The C++ small string optimization

The C++ small string optimization

Scheduled Pinned Locked Moved The Insider News
c++comalgorithmsperformancequestion
7 Posts 4 Posters 0 Views 1 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.
  • K Offline
    K Offline
    Kent Sharkey
    wrote on last edited by
    #1

    Giovanni Dicanio[^]:

    How do “Connie” and “meow” differ from “The Commodore 64 is a great computer”?

    How long is a string?

    N honey the codewitchH 2 Replies Last reply
    0
    • K Kent Sharkey

      Giovanni Dicanio[^]:

      How do “Connie” and “meow” differ from “The Commodore 64 is a great computer”?

      How long is a string?

      N Offline
      N Offline
      Nelek
      wrote on last edited by
      #2

      Kent Sharkey wrote:

      How long is a string?

      Let's see... s-t-r-i-n-g... I would say 6 chars :rolleyes: :laugh:

      M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

      K J 2 Replies Last reply
      0
      • N Nelek

        Kent Sharkey wrote:

        How long is a string?

        Let's see... s-t-r-i-n-g... I would say 6 chars :rolleyes: :laugh:

        M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

        K Offline
        K Offline
        Kent Sharkey
        wrote on last edited by
        #3

        Bzzzt! I said, "a string" :) ;P

        TTFN - Kent

        N 1 Reply Last reply
        0
        • K Kent Sharkey

          Bzzzt! I said, "a string" :) ;P

          TTFN - Kent

          N Offline
          N Offline
          Nelek
          wrote on last edited by
          #4

          Nitpicky... :doh: :laugh: :laugh:

          M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

          1 Reply Last reply
          0
          • K Kent Sharkey

            Giovanni Dicanio[^]:

            How do “Connie” and “meow” differ from “The Commodore 64 is a great computer”?

            How long is a string?

            honey the codewitchH Offline
            honey the codewitchH Offline
            honey the codewitch
            wrote on last edited by
            #5

            That's actually a good question, Ken. The article didn't cover it and presumably it's an implementation detail, but it would be one that would be good to know as a developer since it has so much different dynamics about it, by which I mean, SSO creates more locality and since it is not heap oriented, "short" strings can be stored contiguously in memory using std::vector. That's my takeaway. But, here's the downside they didn't mention. It makes std::string stack heavy - unless there's some magic there I don't understand. On IoT that's a problem, and looking at the asm output at godbolt.org for things like even declaring an iostream makes me shy well away from it there. I've taken to rewriting a lot of the functionality in the STL in my C++ IoT applications because as The STL has evolved it has gotten less and less friendly to little processors like the ones I use daily. Now, that's unfortunate, but I don't want it to be read as a criticism. An AllWinner H3 1Ghz quad core, running even 128MB of DDR3 will have no trouble with modern STL, and these ARM Cortex As are seemingly a big part of the future (and present) of small smart computing. It's moving there. But the hardware at the IoT level isn't quite up to the software. It's being sorely outpaced at the bottom end. For perspective, let me put it in US dollars A Sunxi AllWinner H3 SoC with a quadcore 1GHz ARM Cortex A53 CPU+ Mali GPU, and 128MB with DDR3 can be had in terms of components (sans supporting capacitors, power supply, and stuff - just SoC, RAM and eMMC) for $13-$18/per depending on which parts you source stateside (some you have to get out of Asia) An Espressif ESP32S3 with "SoC" with a dual core 240MHz CPU (no GPU) but with 512kB embedded SRAM and 8MB of PSRAM, + 16MB of internal flash storage (requiring no external memory or flash) can be had for $4.31/per stateside. And this is a very capable chip as IoT class stuff goes. I don't count the RPi among this class. The ESP32S3 and chips like it are the little IoT widget class chips, and they don't run the STL very well. The std::string optimization seems like it makes a bad situation worse in some respects, in terms of stack bloat. You often don't have dynamically growable stacks or even much room on the stack to begin with. printf is bad enough. You start throwing a bunch of std::strings at it and pretty soon you're in real trouble.

            To err is human. Fortune favors the monsters.

            1 Reply Last reply
            0
            • N Nelek

              Kent Sharkey wrote:

              How long is a string?

              Let's see... s-t-r-i-n-g... I would say 6 chars :rolleyes: :laugh:

              M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

              J Offline
              J Offline
              Joe Woodbury
              wrote on last edited by
              #6

              7 - Terminating Zero 9 if Pendant Who Shall Not Be Named gets his way.

              N 1 Reply Last reply
              0
              • J Joe Woodbury

                7 - Terminating Zero 9 if Pendant Who Shall Not Be Named gets his way.

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #7

                8 If you consider the PLC Strings.

                M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.

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


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups