I'm trying to find all instances in a C program that I've written in which I can improve performance. In a few places the program operates very slowly on account of large arrays allocated to the heap, where some of these arrays are integer arrays. I've read, here on stackoverflow and through other sources, that we should always make use of "unsigned" if there is no instance of a negative integer.
While I don't have many instances of division by factors of two, where performance could see a significant boost by making this change, is there a difference in the handling of memory for a large array of int vs. unsigned int? Similarly, does initializing a large array of ints with calloc operate differently when initializing the same array with unsigned int?
Thanks!
In ISO C (C99), int
is signed and has a minimum range of at least -32767 through 32767 include,
unsigned int
is to 0 through 65535 include.
They are both coded on the same amount of bits, and thus, allocating X number of int
and X number of unsigned int
does not make a single difference.
As Mat pointed out, calloc
doesn't even care what types you're giving it.