Announcement

Collapse
No announcement yet.

Byte Vs. Integer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Byte Vs. Integer

    Pretty simple question. If I have a very basic value that I don't need to exceed 100, what type of variable should I use: a byte, or an integer?

    I know on the technical end there's a bit of conversion that needs to happen for a byte to convert to an integer, as almost all Blueprint operations are done in integers. But at the same time, I really don't need the tremendous size of a 64-bit or 32-bit integer, which are 8-4 times as memory-intensive as a single 8-bit byte: I just need a basic value.

    This is probably a completely pointless question to ask because the size of one integer is hardly worth mentioning, but I'm asking anyways because if this item is going to be duplicated around several hundred times, if there is a benefit to using one method over the other, I'd like to know.

    #2
    Well, I have variables that never go over 100 (say, Gender [1,2], HairStyle [1-10], and so on), and I used byte on it. I'm one of the guys that say that the less bytes you send over the network, the better. Without you noticing, by using Integers you might end up using alot of bandwidth... you might not notice it with 10-50 players, but you will eventually notice something reaching 200+ (taking into account all the other stuff being send/received from/to the server/client)

    I'd go with bytes

    Comment


      #3
      If I have a very basic value that I don't need to exceed 100, [...] I really don't need the tremendous size of a 64-bit or 32-bit integer,
      Well, if you have more than only one value, you could combine them into an integer. Like RGBA values are encoded in a 32 bit value.
      Just multiply/divide your values by 256, 655535, etc. to access them. (Or bool them against bitmasks) You just incurr this additional operation and for other datatypes like boolean, the savings are even greater.

      I'm one of the guys that say that the less bytes you send over the network, the better. Without you noticing, by using Integers you might end up using alot of bandwidth..
      This way you would also save the protocol overhead of sending multiple bytes. With sending a 32 bit integer you can send 4 gender/hairstyle, etc. data.

      If only BP had bit shift/rotate functions. Even assembler can do that
      Last edited by KVogler; 02-27-2016, 08:23 AM.

      Comment


        #4
        That kind of optimization seems very extreme. I just finished making a Blueprint to generate the placement of static meshes for a Greek-style fence, and one of the variables is just a number for however many posts the fence should have. While there is some concern while dragging the slider up and down in the editor, it's not a lasting problem as the byte for most objects are converted upon being changed, not ticked once per frame. It seems there's really not much of a difference using Bytes or integers, even though bytes require computational conversions while integers cost more memory. The differences are very negligible.

        Comment


          #5
          The only thing you might want to consider is that many C++ and C compilers align memory on whole-word (that is, 32 or 64 bit, depending on the processor) boundaries. Fetching memory is much, much more efficient this way. Therefore, if you have two byte sized variables; you might expect them to only take up two bytes of memory; but when you get into alignment, it could easily still be eight or sixteen bytes regardless of their size. For an IDE like UE4, this is likely taken care of behind the scenes.

          I painfully remember days, say twenty years or more back, when we used to use odd combinations of unions and structs just to get around this. It's laughable to think that this is going to be a problem on a modern computer, outside of edge cases; but it does still exist. (It's a very real concern if you're working with something like an Arduino.) For many of my projects, I'll choose an int or float over a byte simply because look-up time is faster for them, and there is no guarantee of memory saving (only a possibility).

          If you're really worried about the memory ratio between an int and a byte, though, it's probably time to upgrade your rig, man!

          Comment


            #6
            The network today is already very established, a byte here and there isn't going to make a difference. Use whatever works.

            Comment


              #7
              Originally posted by Simple2012 View Post
              The network today is already very established, a byte here and there isn't going to make a difference. Use whatever works.
              I do not agree on this one. There's still a lot of people who haven't access to fast broadband.
              Also it's not about using a few bytes vars here and there, but eventually replace all the integers that don't need to be so. Using more space than what required is a bad practice/poor coding anyway. IMO using byte or uint8 should always be considered when you don't need to exceed 255

              Comment


                #8
                lol most people around the world barely have speed enough to play a youtube video at 720p;
                That is not "very stabilished" network, not all... That is something around 200kB/s max cap.
                | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                Comment


                  #9
                  Developing on NWN1 for a persistent server gave some real insight into how Bioware set up their networking. Their requirement is 22kbps for each any every client connection (run serially for each client). So for the OP this is the first number you need to figure out (my budget is set to 54kbps). After that it is simply a matter of what variables need to be stuffed into the stream spec. The difference in speed between a Byte and an Integer is nothing and the memory is nothing in a 32 or 64bit system as mentioned above.

                  In my real life job I work in the Programmable Logic Controller (PLC) industry and am very good at what I do. There are Bools, Bytes, Ints (16 and 32), Floats....simple as that. When doing telemetry (networking) it is extremely important to do most of the traffic in 16bit Integer (Floats are local use only. Radio Telemetry is usually 1200/4800/9600baud and handles other than Ints poorly). So bools and bits are 'packed' into an integer before sending and 'unpacked' on the other end to be used. Since ~1998 I have rarely used Bytes any longer because of the additional pain it is to work with them. Most compare and math functions/blocks are either in Integer or Float....which means doing masking on the Ints with Hex to do math for Bytes....Really worth the effort? Lastly, to troubleshoot someones logic when they used Bytes is a pain in the ***.

                  So my solution while I was in Unity (based upon Bioware NWN1 experiences) was to run a change request heartbeat on 500ms intervals for variables that only change so often. I run these with Ints and let the code do the work when the info has changed. I will be using the same technique in UE4 but just have not gotten there yet in the conversion process.

                  Just my two coppers. lol

                  Comment


                    #10
                    Originally posted by snaiperskaya View Post
                    I do not agree on this one. There's still a lot of people who haven't access to fast broadband.
                    Also it's not about using a few bytes vars here and there, but eventually replace all the integers that don't need to be so. Using more space than what required is a bad practice/poor coding anyway. IMO using byte or uint8 should always be considered when you don't need to exceed 255
                    32 bit integer is 4 bytes.
                    4 bytes
                    if you have a 1 kb line, you can transfer 250 integers per second.
                    Let me give you a hint, today none has a 1 kb line.
                    http://www.internetsociety.org/map/g...ad-speed-fixed
                    https://www.statista.com/statistics/...ed-by-country/

                    On 144th place we have "Niger" (I never even heard of em), they have 0.6/0.2 MB
                    That is 600000/200000 b/s. i.e. you can download 150000 integers/s or

                    I sincerly think that an integer here and there isn't going to make any difference.
                    In that case, you would merit more spending time trying to optimise other things, such as creating well defined structures and refraining from sending redundant information.
                    Putting effort to change integers to bytes really isn't worth it. It may have been worth it 10 years ago on embedded systems, but this is 2017. If they don't have the Internet speed to deal with a few computers, then that'll be the least problem. They most likely won't be able to sustain your game with their PC either ;D

                    edit:
                    But of course, using unsigned integers is something I would recommend, but not for memory reasons, but because a uint is positive, and it should always be positive. So using a uint on for example a persons HP would make a lot of sense, since it's not supposed to go below 0.
                    Last edited by Devgroup; 03-10-2017, 06:45 AM. Reason: added info about uint

                    Comment


                      #11
                      Originally posted by BrUnO XaVIeR View Post
                      lol most people around the world barely have speed enough to play a youtube video at 720p;
                      That is not "very stabilished" network, not all... That is something around 200kB/s max cap.
                      I should've mentioned in my post above, a 720p youtube video is definitely more than 200 kB/s.
                      https://support.google.com/youtube/answer/2853702?hl=en
                      720p
                      - Resolution: 1280x720
                      - Video Bitrate Range: 1,500 - 4,000 Kbps

                      Comment


                        #12
                        Well, 200kB IS 2000 Kbps. Again, it is not "definitely more"; it's the average range of (1500 to 4000 kbps).
                        | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                        Comment


                          #13
                          And 4000 kbps is 500 kB/s.
                          Although I must correct myself, the reference I used was for YouTube's live stream. Which is not using the same bitrate as their videos.
                          The videos has a higher bitrate which is https://support.google.com/youtube/answer/1722171?hl=en

                          Type Video Bitrate, Standard Frame Rate (24, 25, 30) Video Bitrate, High Frame Rate (48, 50, 60)
                          720p 5 Mbps 7.5 Mbps

                          So a normal 720p video with 24-30 fps would require 5 Mbps, which is 0.625 MB/s

                          Edit:
                          Don't forget we're comparing with the worst case scenario, which is far from the average case.
                          Last edited by Devgroup; 03-10-2017, 12:06 PM.

                          Comment


                            #14
                            If internet today were any good, nobody would have to pay for services like this to play: http://www.wtfast.com
                            If all we need were only bandwidth we'd be good; outside South Korea, internet services are pretty much very poor and the more data you transfer the less happy players you'll have.
                            LoL is a very very lightweight game and still can't run properly on a lot of those 2Mb connections because the world wide web is total mess, what one takes for granted is almost impossible for others...
                            It's like, graphical fidelity, the more you have it the less people will be able to run it. If he can reduce traffic as much as possible, I say go for it.
                            | Savior | USQLite | FSM | Object Pool | Sound Occlusion | Property Transfer | Magic Nodes | MORE |

                            Comment


                              #15
                              Originally posted by BrUnO XaVIeR View Post
                              If internet today were any good, nobody would have to pay for services like this to play: http://www.wtfast.com
                              If all we need were only bandwidth we'd be good; outside South Korea, internet services are pretty much very poor and the more data you transfer the less happy players you'll have.
                              LoL is a very very lightweight game and still can't run properly on a lot of those 2Mb connections because the world wide web is total mess, what one takes for granted is almost impossible for others...
                              It's like, graphical fidelity, the more you have it the less people will be able to run it. If he can reduce traffic as much as possible, I say go for it.
                              Sorry but are you aware of what that website does? It has absolutely nothing to do with the bandwitdh as the amount of information that needs to be transferred for your game to function properly, has to remain the same.
                              The only thing that website could possibly do, is to attempt to decide a smarter route by choosing a "smart" DNS, thereby hopefully - potentially - lowering the latency, which is the end-to-end delay.
                              And according to a partially untrustworthy source, League of Legends uses about ~3.5kB in and 0.6kB out per second (~6-7 MB incoming data and ~1 MB outgoing for a 30 min game quoted from Kbox, software engineer at LoL).
                              http://forums.euw.leagueoflegends.co...d.php?t=191041
                              So whether LoL lags due to insufficient bandwitdhs or not is up to you to verify if you're interested. I'm just saying, The internet today will seriously not be affected if you use bytes instead of integers.
                              Like I said before, you're better off just using integers, thereby speeding up your development process allowing you to spend more time on optimising things that actually do matter.

                              Comment

                              Working...
                              X