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
  1. Home
  2. The Lounge
  3. Do you think much about your shorts?

Do you think much about your shorts?

Scheduled Pinned Locked Moved The Lounge
csharpasp-netcomdata-structuresperformance
38 Posts 18 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.
  • L Lost User

    The customer ordered it, the hardware company built it, I had to program it (contract). There were no choices. The hardware company used my software to debug their firmware. (Only way to avoid finger pointing).

    It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

    J Offline
    J Offline
    Joan M
    wrote on last edited by
    #24

    I'm glad you've been so lucky. Congratulations. :thumbsup:

    www.robotecnik.com[^] - robots, CNC and PLC programming

    1 Reply Last reply
    0
    • L Lost User

      In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

      It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

      D Offline
      D Offline
      Daniel Pfeffer
      wrote on last edited by
      #25

      Only when targeting (a) an extremely memory-limited system, or (b) a 16-bit or less processor. (a) may be the case with industrial controllers or the first stage of a bool loader (it is an advantage if the code can run in the processor's internal memory) (b) may be the case for some embedded devices

      Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

      L 1 Reply Last reply
      0
      • L Lost User

        "Not thinking" is not something I ever boasted about. It was a thought exercise; regardless of what the compiler "might do".

        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

        S Offline
        S Offline
        Slacker007
        wrote on last edited by
        #26

        an int is just fine. for me, it is a no brainer. If you want to spend hours thinking about it, go for it.

        1 Reply Last reply
        0
        • D Daniel Pfeffer

          Only when targeting (a) an extremely memory-limited system, or (b) a 16-bit or less processor. (a) may be the case with industrial controllers or the first stage of a bool loader (it is an advantage if the code can run in the processor's internal memory) (b) may be the case for some embedded devices

          Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #27

          Yes. My first job was an IBM installation. Little signboards around the office, and all they said was "Think". One of the few joys left in life when you can.

          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

          1 Reply Last reply
          0
          • L Lost User

            I worked with PLC's, etc. Never had to sweat 1 or 2 bytes; getting the storage architecture right was more important.

            It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

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

            I have always preferred the 2 bytes distribution for variables (WORD or INT) due to the endian changes, it is already painful enough to deal with it without having to increase the difficulty messing with more than a variable in the "same space" On the other hand, when staying in the PLC I have used a lot of BYTE variables. Specially when grouping bits to be masked or moved from one place to another.

            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
            • L Lost User

              In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

              It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

              M Offline
              M Offline
              Mike Hankey
              wrote on last edited by
              #29

              More so now because of winter my legs are shockingly white.

              I'm not sure how many cookies it makes to be happy, but so far it's not 27. JaxCoder.com

              1 Reply Last reply
              0
              • L Lost User

                In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                R Offline
                R Offline
                Rick York
                wrote on last edited by
                #30

                It depends on the target environment. I work on HPC stuff using CUDA and GPUs and with them using a short instead of an int can make a significant difference in performance and Nvidia includes this point in their documentation. With CUDA, using an signed value is almost always preferred over an unsigned value for performance reasons also. They have quite a number of odd, little quirks regarding optimal performance. For standard desktop CPUs I rarely concern myself with that issue. The only other environment I work in these days is embedded code in scanning cameras and I don't care there either.

                "They have a consciousness, they have a life, they have a soul! Damn you! Let the rabbits wear glasses! Save our brothers! Can I get an amen?"

                1 Reply Last reply
                0
                • L Lost User

                  In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                  It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                  R Offline
                  R Offline
                  Ron Anders
                  wrote on last edited by
                  #31

                  This morning I took my dog out for a romp. it was -18 out. I remembered how I used to wear shorts at the same time of day in the summer.

                  1 Reply Last reply
                  0
                  • L Lost User

                    In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                    It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                    M Offline
                    M Offline
                    Martin ISDN
                    wrote on last edited by
                    #32

                    original Apollo 11 guidance computer was 16bit someone said this was a rework from FORTRAN to C maybe this is indeed for 16bit hardware

                    1 Reply Last reply
                    0
                    • L Lost User

                      Oh Well, I wish you would have commented sooner. I found a bug in your json parser but didn't want to tarnish your article comment section. :-O Let me know if you want to discuss it here and I'll go over and delete it.

                      H Offline
                      H Offline
                      honey the codewitch
                      wrote on last edited by
                      #33

                      I'm about to fix it. I was at sister's yesterday so I couldn't.

                      Real programmers use butterflies

                      1 Reply Last reply
                      0
                      • L Lost User

                        In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                        It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                        R Offline
                        R Offline
                        Rusty Bullet
                        wrote on last edited by
                        #34

                        NASA spacecraft still run on 286 instruction sets, so it would depend on where the code is being run. Space center code would be a different architecture. EDIT: PowerPC

                        1 Reply Last reply
                        0
                        • L Lost User

                          In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                          It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                          D Offline
                          D Offline
                          davecasdf
                          wrote on last edited by
                          #35

                          I don't, I just grab the first pair out of the drawer. Oh, shorts, Keystone cops? Pink Panther? --NASA they could be using an 8 bit CPU. More likely a 16 bit, but probably not something that's not 16 bit word directly addressable. Shorts may be faster access. When and for what was the code written?

                          1 Reply Last reply
                          0
                          • L Lost User

                            You make a lot of assumptions.

                            It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                            O Offline
                            O Offline
                            obermd
                            wrote on last edited by
                            #36

                            No, your assessment that they're making an invalid tradeoff is the assumption. JPL writes real-time code for memory limited systems that cannot fail. Their use case is far different from almost everyone else.

                            1 Reply Last reply
                            0
                            • L Lost User

                              In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                              It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                              U Offline
                              U Offline
                              User 13269747
                              wrote on last edited by
                              #37

                              Quote:

                              In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best?

                              Use a size_t, unless you have a specific reason that needs negative numbers. The reason is because the compiler can warn you if you are writing a loop that may never terminate (checking for <=0 zero, for example). For fast execution reasons, use unsigned int or int as they are guaranteed to be the natural word size of the platform. For space reasons using 8 bit and 16 bit integers make sense, but don't use 'short' or 'long' etc, they are not guaranteed to have any specific width. If you need a specific bit width use uint8_t/int8_t/int_least8_t/uint_least8_t and their 16, 32 and 64 counterparts. Using 'short' and writing code that assumes it is 16-bit or using 'int' and writing code that operates on it as a 32 bit integer is guaranteed to break on some platform; those are latent bugs because overflows are undefined behaviour and the compiler is allowed to generate code that crashes when you overflow a signed integer type (yes, that's happened to me on at least one ARM platform when compiled with clang and -O3). In general, avoid using bare int/short/long long/long because the compiler cannot warn you if you are writing bugs.

                              1 Reply Last reply
                              0
                              • L Lost User

                                In looking at this JPL/Nasa code, it makes references to doing this and that for "performance". In some cases, their loop variable is an int; in others a short; in others a long. Given a choice which is best? Probably an int, unless you "need" a long. Ironic that for the sake of "storage" (2 bytes), they've sacrificed performance. [asp.net - Why should I use int instead of a byte or short in C# - Stack Overflow](https://stackoverflow.com/questions/1097467/why-should-i-use-int-instead-of-a-byte-or-short-in-c-sharp)

                                It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it. ― Confucian Analects: Rules of Confucius about his food

                                B Offline
                                B Offline
                                BotReject
                                wrote on last edited by
                                #38

                                In the old days we had to worry about every byte of memory and every tick of the clock, but with modern computers, it goes without saying that memory and speed are rarely limiting, unless: you were looping objects or something large, or you were designing a real-time app like a missile-tracking system. Some coders opt for 'better performance' even when it actually makes no significant difference, simply because they can.

                                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