When to use short?

前端 未结 4 648
心在旅途
心在旅途 2021-01-20 03:23

Say I\'m looping through like 20/30 objects or in any other case where I\'m dealing with smaller numbers, is it a good practice to use short instead of int?

I mean w

4条回答
  •  不要未来只要你来
    2021-01-20 03:51

    An int uses 32 bits of memory, a short uses 16 bits and a byte uses 8 bits. If you're only looping through 20/30 objects and you're concerned about memory usage, use byte instead.

    Catering for memory usage to this level is rarely required with today's machines, though you could argue that using int everywhere is just lazy. Personally, I try to always use the relevant type that uses the least memory.

    http://msdn.microsoft.com/en-us/library/5bdb6693(v=vs.100).aspx

提交回复
热议问题