1

Do 32-bit types save memory on 64-bit systems? Also, is the memory divided into individual bytes or multi-bytes (32/64-bit)?

I know that the processor processes all data as 64 bit, filling in the missing data. So would a 32-bit int slow down the calculation? Or would the int be stored as 64 bit anyway?

I ask because I was trained for micro-controllers, where memory and storage are limited, and I'm wondering whether it's at all relevant on smartphones and computers.

Thanks.

  • Caches are King on modern processors. You don't get double the cache size. Many 64-bit compilers still use a 32-bit *int* type. – Hans Passant Jul 08 '14 at 23:47

2 Answers2

0

The size is not the issue, the compiler will generally has that out. What is important to performance is the structuring of the data storage.

Pad data structures so that every data element of data structures and arrays is aligned to a natural operand size of 64 or 128 bit. Also structure the data into 64 byte segments to match the 64 and 128 byte L1 cache line size. 64 bytes on Intel Pentium 4, Intel Xeon, Pentium M, Intel Core Duo processors, 128 bytes on Pentium 4 and Intel Xeon processors.

You do not want to access variables stored in two different cache lines. In a routine use variables defined locally rather than globals. If globals are to be accessed repeatedly over an extended period, copy them to the variables defined on the local stack.

Misunderstood
  • 5,534
  • 1
  • 18
  • 25
0

Unless you have huge arrays (hundreds of MB or even GBs large), you won't save much memory on using 32-bit types on modern systems. If you are doing math (eg. cryptoalgorithms), operating with 64-bit integers should give you performance boost.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121