Using Int32 or what you need

If you use Int32 in those places where you know that the value will not be higher than 32,767?

I would like to keep the memory down, hoever, using casts everywhere, just to perform simple arithmetic becomes annoying.

short a = 1;

short result = a + 1; // Error

short result = (short)(a + 1); // works but looks ugly when does lots of times

What would be better for overall application performance?

+3
source share
4 answers

If you create large arrays, then it can save a significant part of memory for using narrower types (fewer bytes), since the size of the array will be "type width" * "number of elements" + "overhead" ,.

, , , . 32bit = 4 . - 4- .

structs\classes :

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.structlayoutattribute(VS.71).aspx

, : " - ".

API, , int .., , API- , , ints.

+4

, int . int , , .

+8

3 , int32:

  • .
  • .
  • , .

Windows, , , .

+1

If you do not create 100 thousand participants, then saving the space of several bytes here and there will not make any difference on any modern machine. I think that there is a principle of premature optimization. It may make you feel better, but you are not getting any of this. IMO - only optimizes memory usage, if in fact you are using a lot of memory.

0
source

Source: https://habr.com/ru/post/1746674/


All Articles