Search Unity

Actual bit sizes in Unity for [char, short, int, float and boolean] (Windows, C#)

Discussion in 'Multiplayer' started by rbx775, Jun 9, 2016.

  1. rbx775

    rbx775

    Joined:
    Aug 16, 2010
    Posts:
    102
    I thought I'd do some research on variable Type sizes before starting to program my Network.
    But hell, is it confusing...
    What I learned so far: it seems to be platform and language dependant.

    I found varying informations about it on Wikipedia,
    where a short data type for example, could range from 2 bit to 16 bit...
    https://en.wikipedia.org/wiki/Integer_(computer_science)

    #1 So does anyone know more about this mysterious voodoo (How can I test it)?
    (How many bits does a char, short, int, float, boolean actually use up in Unity 3D, C# ?)

    #2 Does it even work this way ?
    Or doesnt it make any difference at all to try to send smaller data Types over Unet
    (e.g. ushort instead of int, ect...) ?

    #3 Does it differ from target platform to target platform ?
    What if a Linux user joins a Windows users lobby ?


    Could a programming god descent from his heavenly realm and clear things up for a nooby ?
    Thanks ! :)
     
  2. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    Nothing is smaller than a byte. Find out exact sizes with sizeof() :)

    The different datatypes should be the same across all operating systems. If they're not I want to kick someone.
     
  3. rbx775

    rbx775

    Joined:
    Aug 16, 2010
    Posts:
    102
    Oh WOW ! That was fast and easy, thank you orb !
    I also noticed that my confusion mainly came simply from misreading the wiki page...
    short was listed with 16bit, and again further down as 2byte. my bad,
    but you cleared things up for me big time, thank you ! I lack a good education in computer science.

    For anyone in the future whos as nooby as I was; Heres a quick overview:

    boolean : 1byte

    byte : 1byte (obviously)
    short : 2bytes
    int : 4bytes
    long : 8bytes

    char : 2bytes

    float :4bytes
    double :8bytes