How much does memory usage cost when switching to 64-bit?

When moving an application from 32-bit to 64-bit, where will the memory usage increase?

I understand that pointers are double in size, I suspect that the characters in the string are “grouped” in order to use memory more efficiently (so I won’t use much more memory).

Where else will memory usage increase? Is there somewhere that it will decrease, or where non-arithmetic operations will see an advantage in speed?

+7
c ++ c memory-management 64bit
source share
4 answers

You can see additional alignment to cost a few extra bytes here and there. The code is likely to be larger due to 64-bit constants in operands.

In terms of speed, you may experience slowdown due to increased memory usage. The CPU cache will fill up faster.

I saw significant speed advantages from x86 to x64 because x86 has far fewer registers than the x64 architecture. Compilers use additional registers for better code optimization. I saw 15% acceleration on identical hardware.

+7
source share

As you noticed, there will be more pointers. Depending on the processor architecture, there may also be ints and / or longs . Rows must be the same size, but to be more efficient, they must be calculated differently. As a rule, alignment of the memory of data structures at 64-bit boundaries in most cases will lead to increased fragmentation.

In addition, the address space of your process can appear (in many architectures) much more with stack frame pointers that appear in large memory (and grow down), but since they are always virtual memory pointers, the actual physical memory used by your application is usually significantly less.

+3
source share

There are several cases where you can save memory. Actual code may be a little shorter in places, because fewer downloads / storages are required due to the increase in the number of registers. A standard calling convention, for example, passes parameters to registers.

In general, a 64-bit application is likely to use a little more memory than 32-bit. But that will not be a bargain.

+2
source share

Depending on the architecture, the code may also grow. Global variables and constant are often referenced via absolute addresses (which are moved by the program loader), these links are 64-bit in 64-bit mode. On x64 there is an explicit mov command for 64-bit constants, so the program will only increase in size of the constant. Jump and call commands may also increase, but this depends on many parameters of the compiler and linker. On other architectures, this can be even worse. For example, in SPARC, when switching from 32 to 64 bits, the code can increase significantly. Since sparc does not have an instruction that can load more than 22 bits, when loading a 32-bit address of a global variable or constant, it needs 2 instructions, to load a 64-bit constant it even needs 5 instructions with 3 registers. By increasing the pressure in the register, the compiler often skips optimization opportunities, making the code much larger than necessary.

+2
source share

All Articles