Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use integers smaller than 32bit?

I always like to use the variable with the smallest size that will work just fine, But would this really gain me if I used short byte integers instead of integer, and the memory is 32bit word addressable, Does the compiler do something to enhance memory usage ?

like image 208
Mohamed Atia Avatar asked Oct 25 '09 21:10

Mohamed Atia


1 Answers

For local variables, it probably doesn't make much as much sense, but using smaller integers in structures where you have thousands or even millions of items, you can save a considerable amount of memory.

like image 61
Adisak Avatar answered Sep 21 '22 09:09

Adisak