Reputation: 51
I have two question.
First question:
How does using int instead of long reduce amount of bytes in program? As I understand, we allocate variable, that is, we occupy one address and if we use 64 bit architecture we have 64 bit for every address of memory.
Second question:
How does data which is less than 64 bits is contained in address of memory? It occupies first elements and then writes 0 in other cells?
Thank you
Upvotes: 1
Views: 339
Reputation: 93172
Most 64 bit architectures are still byte addressed architecture, i.e. each address refers to 1 byte. So using a 32 bit datum instead of a 64 bit datum makes it occupy only 4 addresses instead of 8 addresses, saving half the space.
On a 64 bit architecture that is a word addressed architecture (i.e. each address refers to one 64 bit word), your first remark is correct. Using 32 bit variables does not save memory. As for your second question, zero-extending the datum to fit into 64 bits is a common choice when dealing with 32 bit data on word addressed architectures.
Upvotes: 4