Is there a relationship between integers and register sizes?

Recently, I was interviewed in a recent interview with string manipulation and asked to optimize performance. I had to use an iterator to move between TCHAR characters (with UNICODE support - 2 bytes each).

Without thinking about the length of the array, I made a curatorial error, not using size_t, but int for iteration. I understand that it is not compliant and not protected.

int i, size = _tcslen(str);    
for(i=0; i<size; i++){
   // code here
}

But the maximum memory that we can allocate is limited. And if there is a relationship between int and register sizes, it may be safe to use an integer.

For example: without any virtual matching tools, we can only display 2 bytes of register size. Since TCHAR is 2 bytes long, half that number. For any system that has an int as 32-bit, this will not be a problem, even if you are not using an unsigned version of int. People with a built-in background are used to counting int as 16 bits, but memory size will be limited on such a device. So I wonder if there is an architectural solution to fine-tune between integers and register sizes.

+3
source share
6 answers

The C ++ standard does not specify the size of an int. (He says that sizeof(char) == 1and sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long).

Thus, . ++ 256 32- . .

, int CPU, , , .

a int , , . , , . ( int , short.)

( , int 32-, , , --- 32- , )

+4

, , / int, . , (.. ), (, DOS : ). , int , "" , .

+3

AFAIK, int.

, , , :

#ifdef WIN32 // Types for Win32 target
#define Int16 short
#define Int32 int
// .. etc.
#elif defined // for another target

.

+2

, , ( , , , ?).

( ), , . , , , , x86 . Intel , ( , ) . , , . , .

- - speeedwise - , .

+2

, C ( 2.2) int " , ". ++ ( 4.6) , int . "

, : " , , ."

+2

. , . 64-, ( ) 64-, 32-. , , 64- .

, - , , , 8086 " real mode".

+2

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


All Articles