title: Is there a relation between integer and register sizes?
body: <p>Recently, I was challenged in a recent interview with a string manipulation problem and asked to optimize for performance. I had to use an iterator to move back and forth between TCHAR characters (with UNICODE support - 2bytes each). </p>
  
  <p>Not really thinking of the array length, I made a curial mistake with not using size_t but an int to iterate through. I understand it is not compliant and not secure.</p>
  
  <pre><code>int i, size = _tcslen(str);    
  for(i=0; i&lt;size; i++){
     // code here
  }
  </code></pre>
  
  <p>But, the maximum memory we can allocate is limited. And if there is a relation between int and register sizes, it may be safe to use an integer.</p>
  
  <p>E.g.: Without any virtual mapping tools, we can only map 2^register-size bytes. Since TCHAR is 2 bytes long, half of that number. For any system that has int as 32-bits, this is not going to be a problem even if you dont use an unsigned version of int. People with embedded background used to think of int as 16-bits, but memory size will be restricted on such a device. So I wonder if there is a architectural fine-tuning decision between integer and register sizes.</p>