Quote:
Originally Posted by fakie_flip
2) Then why does a 64 bit OS have higher memory requirements than the same OS in 32 bit?
|
1) X86 instructions in machine language vary in length from single byte instructions up to quite long (I'm not sure of the max). Average instruction length is larger in x86-64 than in 32-bit x86. That is partially balanced by some situations in which the compiler emits fewer instructions in x86-64 than in 32-bit for the same C code. But only partially balanced. On average, the same code compiles larger on x86-64 than 32-bit.
2) Pointers are twice as big in x86-64 as in x86. In many programs, a large fraction of the data is pointers (rather than basic types like int, char, double, etc.).
3) Considering a whole OS, rather than just a program, you should also consider that it is common to run a few 32-bit programs on a 64-bit OS, but you can't run any 64-bit programs on a 32-bit OS. A 32-bit program and 64-bit program running at the same time that use shared libraries compiled from the same source code, can't use the same binary shared libraries. So running more than one bit size of application means more memory is used by the whole system for shared libraries.
4) If I understand correctly (I'm not sure of this one) the exception handling for C++ for x86-64 is a totally redesigned system meant to minimize the run time overhead of having exception handling (the time it take to
not have an exception) at the expense of both memory size and the execution time when you actually do have an exception.
Lots of minor reasons as well, such as a more layered page table structure in the kernel for mapping virtual addresses to physical addresses. (Compared to 32-bit non PAE, the page tables also have half capacity, so you need twice as many. 32-bit PAE has the same capacity per page table as x86-64).
Quote:
Originally Posted by fakie_flip
Is there a gcc flag I can use to tell it to use only 4 bytes for int on a 64-bit machine instead of 8 bytes?
|
int is 4-bytes by default in gcc for x86-64.
There is a gcc switch
-m32 that you can use on a 64-bit Linux (assuming 32-bit support is installed) to build your entire application as 32-bit, so pointers and longs are 32-bit just as on a 32-bit Linux.
If your application manipulates mainly pointers (rather than ints or doubles, etc.) and doesn't need more than 4GB per process. It may take significantly less memory and less CPU time run as a 32-bit application under a 64-bit OS than run as a 64-bit application.
It may seem bizarre to non programmers, but a lot of programs do manipulate pointers far more than actual data.
Most programs have no need to exceed the 4GB limit on a 32-bit program in a 64-bit OS. Even if the whole system has and needs far more than 4GB of physical ram, individual processes usually need less than 4GB of virtual ram each.