Search Unity

ints/floats/strings and the bandwidth they use

Discussion in 'Multiplayer' started by gsus725, Oct 25, 2012.

  1. gsus725

    gsus725

    Joined:
    Aug 23, 2010
    Posts:
    250
    Hey I was searching google to find info on how much bandwidth these different types of things send, but I couldn't find anything, so I'm now asking here.

    I've read some things about how different types of numbers use different amounts of bandwidth, like how there are 4 bit numbers, 8 bit, 16, 32, 64..And that this may have something to do with binary. Numbers 1-255 are low bandwidth etc

    Long story short, can you refer me to any reading material on this? I must be using the wrong search terms in google since I know so little about this subject. I don't know what search terms to use. Thanks.
     
  2. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    int = 4 bytes, float = 4 bytes, short = 2 bytes, long = 8 bytes, double = 8 bytes, byte = 1 byte (ooh!), bool = 1 byte, string = 2 bytes per character (more or less).

    --Eric
     
  3. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    strings are usually 2 + (2 * characters)
     
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    are doubles any slower in mono compilation? I ask because a) mono isn't as optimised as .net, particularly the version unity uses and b) there's no evidence that the compiler packs floats on 64 bit architecture where possible to save time on 64 bit.

    So is there any measurable speed difference between doubles and floats?

    Personally I don't think so - but the habit of appending f is probably not going to go anywhere for anyone.
     
  5. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    For strings I'd use UTF8 and to bring it down to ~1byte/char [barring exotic languages].
     
    Last edited: Oct 26, 2012
  6. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    fholm turned me on to SlimMath, a really nice .NET half precision library that works great in Unity. Really nice for packing all your floats into 2 bytes before serializing or RPC'ing them, and unpacking them on the other side. Cut all my bandwidth in half.
     
    moco2k likes this.
  7. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    This sounds like a nice way to significantly reduce bandwidth consumption indeed. Thanks for these information.
     
    Last edited: Dec 10, 2015
  8. unitywlp

    unitywlp

    Joined:
    Jan 3, 2014
    Posts:
    146
    can you share slimmath code ?