Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should we build 64 bit targets for C++ application? [closed]

This is a very basic doubt that I have. I am not an IT or CS guy so please try to explain in simple language. Now why I am asking that question is that because we can run 32 bit apps in 64 & 32 bit OS's. AFAIK the data types for 64 bit take double amount of memory than 32 bit apps. Also 64 bit apps can only run on 64 bit OS's. Then why take the trouble of building 64 bit applications? Perhaps thats why Firefox is available only in 32 bit??? Sorry if this question is not on par with the standards of SO, but I just cant control stop thinking about the same. Thank You.

UPDATE: Somehow there seems to be a confusion. I did not mean to question why we need a 64 bit architecture machine. I know that 32 bit machines can only use 4GB RAM & 64 bit machines have much higher limit. I was questioning why we need to build 64 bit Applications!

like image 658
Cool_Coder Avatar asked Apr 11 '13 12:04

Cool_Coder


People also ask

Should I use 32 or 64-bit programs?

Simply put, a 64-bit processor is more capable than a 32-bit processor because it can handle more data at once. A 64-bit processor can store more computational values, including memory addresses, which means it can access over 4 billion times the physical memory of a 32-bit processor. That's just as big as it sounds.

What does it mean for a program to be 64-bit?

A 64-bit processor refers to a microprocessor that can process data and instructions in chunks of 64 bits. Microprocessors that can handle 64 bits perform a larger number of calculations per second compared to 32-bit processors.

What is the difference between 64 and 86 bit?

A 32-bit processor on x86 architecture has 32-bit registers, while 64-bit processors have 64-bit registers. Thus, x64 allows the CPU to store more data and access it faster. The register width also determines the amount of memory a computer can utilize.


2 Answers

Aside from the OBVIOUS reasons given above (mainly "using more than 2-3GB of memory"), the reason to compile for 64-bit is that x86-64 has 16 registers, where x86-32 has 8. Since one of those registers is the stackpointer and often rBP is reserved for "framepointer", the actual useful number of registers is 6 and 14 respectively. The additional registers allow, for example, larger number of parameters being passed in registers, and larger number of temporary variables being held in registers within a function. This has a positive effect on the actual execution speed of the code, as every time memory is used instead of a register, AT LEAST it leads to a more complex instruction, and often to an additional instruction having to be used. This in turn makes the code larger when there isn't enough registers.

Generally, 64-bit x86 code runs some 5-15% faster with no modification to the actual algorithms, and typically has . Sometimes algorithms can be changed to gain much more [because for example you can have an array that is indexed by "telephone number", instead of hashing the phone number and then indexing on the hash, or making use of 64-bit integer values instead of 32-bit ones, meaning a speedup of 2x for "half as many operations"].

If it's performance you need from the application, you will have to benchmark (on multiple platforms). There are situations where, for example, larger pointers, mean that cache gets full more quickly and the code ends up running slower because "only half as many linked list entries fit in the cache".

In short: In most cases, 64-bit apps are faster than 32-bit apps doing the same thing.

like image 188
Mats Petersson Avatar answered Oct 10 '22 16:10

Mats Petersson


  • Physical memory

A 32-bit system architecture can directly address only a 4-GB address space. A 64-bit system architecture that is running a 64-bit edition of Windows Server can support up to 1,024 GB of both physical and addressable memory.

  • Better parallel processing

A server that is using 32-bit architecture is limited (Windows OS) to 32 CPUs. Improvements in parallel processing and bus architectures enable 64-bit environments to support as many as 64 processors and provide almost linear scalability with each additional processor.

  • Faster bus architecture

A 64-bit architecture provides more and wider general-purpose registers, which contribute to greater overall application speed. When there are more registers, there is less need to write persistent data to memory and then have to read it back just a few instructions later. Function calls are also faster in a 64-bit environment because as many as four arguments at a time can be passed in registers to a function.

like image 44
Leo Chapiro Avatar answered Oct 10 '22 18:10

Leo Chapiro