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. General Programming
  3. C / C++ / MFC
  4. char to store < 255 or use int

char to store < 255 or use int

Scheduled Pinned Locked Moved C / C++ / MFC
performancesysadmintutorialquestion
10 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.
  • O Offline
    O Offline
    oversight project zero
    wrote on last edited by
    #1

    hi , this is about memory/speed size optim. take this for example: const int cAIMessageRouter_Init_ReserveRegisteredObjectCount = 64; const int cAIMessageRouter_Init_ReserveDelayedMessagesCount = 16; if i replace the int with a char or short.... what would be better.... Size does matter becouse every BIT send to the server .......... How smaller the player data, how faster the server can respond. But i dont know this: is const char value=12; FASTER then const short value=12; const int value=12; or slower?

    T 1 Reply Last reply
    0
    • O oversight project zero

      hi , this is about memory/speed size optim. take this for example: const int cAIMessageRouter_Init_ReserveRegisteredObjectCount = 64; const int cAIMessageRouter_Init_ReserveDelayedMessagesCount = 16; if i replace the int with a char or short.... what would be better.... Size does matter becouse every BIT send to the server .......... How smaller the player data, how faster the server can respond. But i dont know this: is const char value=12; FASTER then const short value=12; const int value=12; or slower?

      T Offline
      T Offline
      tansey4
      wrote on last edited by
      #2

      Try it out yourself by using sizeof and passing each of those items. example: cout << "Size of an integer: " << sizeof(int) << endl;

      O 1 Reply Last reply
      0
      • T tansey4

        Try it out yourself by using sizeof and passing each of those items. example: cout << "Size of an integer: " << sizeof(int) << endl;

        O Offline
        O Offline
        oversight project zero
        wrote on last edited by
        #3

        if i do sizeof(int) i get 32 or 16. With a char i get 8 :-) But if i use a char to hold a integer value of 5, wouldn`t that be slower? becouse chars are mainly used for strings.

        G T T 3 Replies Last reply
        0
        • O oversight project zero

          if i do sizeof(int) i get 32 or 16. With a char i get 8 :-) But if i use a char to hold a integer value of 5, wouldn`t that be slower? becouse chars are mainly used for strings.

          G Offline
          G Offline
          Gerben Jongerius
          wrote on last edited by
          #4

          Characters are represented by a numeric value. It is that value that is stored in your variable not the letter itself, for chars these are the ASCII values. So its just as fast to use a number as it is to use a letter.

          O 1 Reply Last reply
          0
          • O oversight project zero

            if i do sizeof(int) i get 32 or 16. With a char i get 8 :-) But if i use a char to hold a integer value of 5, wouldn`t that be slower? becouse chars are mainly used for strings.

            T Offline
            T Offline
            tansey4
            wrote on last edited by
            #5

            oversight-[project-zero] wrote:

            chars are mainly used for strings.

            Not exactly true. Char's are used for lots of things, including pure data manipulation. It's simply 2 bytes which can be interpreted as an ANSII character. That said, if you're only going to be holding very small numbers like 5 and you're EXTREMELY worried about space/efficiency, you should use BYTE for values which you know will be less than 16. I'm not sure how much time this will all save you to be honest, these types of issues are normally only a passing thought in designing your application because there are so many more design issues that would likely speed up your program much more.

            O T 2 Replies Last reply
            0
            • G Gerben Jongerius

              Characters are represented by a numeric value. It is that value that is stored in your variable not the letter itself, for chars these are the ASCII values. So its just as fast to use a number as it is to use a letter.

              O Offline
              O Offline
              oversight project zero
              wrote on last edited by
              #6

              Thanx. The game (soldner secret wars) i am working on (mainly patches) has many data like: const int max_sounds=5; by using this: const char max_sounds=5; i can optimize SIZE, becouse 20 classes uses 1 class for work that has this defined. or am i wrong? cu

              1 Reply Last reply
              0
              • T tansey4

                oversight-[project-zero] wrote:

                chars are mainly used for strings.

                Not exactly true. Char's are used for lots of things, including pure data manipulation. It's simply 2 bytes which can be interpreted as an ANSII character. That said, if you're only going to be holding very small numbers like 5 and you're EXTREMELY worried about space/efficiency, you should use BYTE for values which you know will be less than 16. I'm not sure how much time this will all save you to be honest, these types of issues are normally only a passing thought in designing your application because there are so many more design issues that would likely speed up your program much more.

                O Offline
                O Offline
                oversight project zero
                wrote on last edited by
                #7

                thanx, at this moment we have still (mod-team) status... and i am the only c/c++ coder. This forum is a great help. (talks are going on about soldner 2 www.secretwars.net= www.soldner.jowood.com) You might wonder why this game source is so complicated ;-) lol. (i hate wings !!!, crappy coders!!!!) i can use a few helping hands making soldner a better game, if you are interested..... The source is like this: dynamics,core etc is defined in classes, DEEP polymorpish and derived stuff. (just defined..... no value`s in c++) The xml and python is used to define the game property`s. Thats called the gdb::xxxxx (game database). The gdb is implemented in c/c++ but called from python and xml. :-) becouse of this complexity, i am seeking for talented coders. At our team talks are going on about a contract with jowood. We where/are a mod team, but i think thats changing rapidly. Jowood needs project zero, without project zero NO soldner. Cu at the soldner battlefield.

                1 Reply Last reply
                0
                • O oversight project zero

                  if i do sizeof(int) i get 32 or 16. With a char i get 8 :-) But if i use a char to hold a integer value of 5, wouldn`t that be slower? becouse chars are mainly used for strings.

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #8

                  oversight-[project-zero] wrote:

                  becouse chars are mainly used for strings.

                  what's that crap ? char is an integer in C/C++, and its name is quite bad as beginners make too much confusion... a char is only a 8 bits integer. in C/C++, there's no high level type for strings. strings are simply char arrays, ended with a char whose value is 0. never using a char will slow down your application compared to an int for such a use... however, you'll have to consider the values stored within... char is a signed type, so stored values between -128 and 127. if you want values from 0 to 255, use unsigned char. and if you want more, use short, int (size is dependant of the plateform ; can be 8, 12, 32 or 64 bits !!! be careful !), long...


                  TOXCCT >>> GEII power
                  [toxcct][VisualCalc 2.20][VisualCalc 3.0]

                  G 1 Reply Last reply
                  0
                  • T tansey4

                    oversight-[project-zero] wrote:

                    chars are mainly used for strings.

                    Not exactly true. Char's are used for lots of things, including pure data manipulation. It's simply 2 bytes which can be interpreted as an ANSII character. That said, if you're only going to be holding very small numbers like 5 and you're EXTREMELY worried about space/efficiency, you should use BYTE for values which you know will be less than 16. I'm not sure how much time this will all save you to be honest, these types of issues are normally only a passing thought in designing your application because there are so many more design issues that would likely speed up your program much more.

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    tansey4 wrote:

                    It's simply 2 bytes

                    false. a char is 8 bits wide, so only 1 byte !!!!!!


                    TOXCCT >>> GEII power
                    [toxcct][VisualCalc 2.20][VisualCalc 3.0]

                    1 Reply Last reply
                    0
                    • T toxcct

                      oversight-[project-zero] wrote:

                      becouse chars are mainly used for strings.

                      what's that crap ? char is an integer in C/C++, and its name is quite bad as beginners make too much confusion... a char is only a 8 bits integer. in C/C++, there's no high level type for strings. strings are simply char arrays, ended with a char whose value is 0. never using a char will slow down your application compared to an int for such a use... however, you'll have to consider the values stored within... char is a signed type, so stored values between -128 and 127. if you want values from 0 to 255, use unsigned char. and if you want more, use short, int (size is dependant of the plateform ; can be 8, 12, 32 or 64 bits !!! be careful !), long...


                      TOXCCT >>> GEII power
                      [toxcct][VisualCalc 2.20][VisualCalc 3.0]

                      G Offline
                      G Offline
                      Gerben Jongerius
                      wrote on last edited by
                      #10

                      It is not so that using integers (32 bits) will slow your applications compared to using chars (signed or not of importance since 8 bit is 8 bit). In game development speed is everything and a 32 bit CPU processes 32 bit values quicker then 8 bit values. So using an int is faster then a char.

                      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