вторник, 19 июля 2011 г.

How much memory can an application access in Win32 and Win64?

When developing a software product for a Windows-family operating system, you must keep in mind the restrictions imposed on sizes of data a program can declare and use. Windows imposes the following 3 types of restrictions on applications:
  • Static data. The restriction is imposed on the size of the program source code itself and the size of statically allocated memory. In C++, such data are usually represented by global variables defined outside procedures. The restriction concerning the size of statically allocated memory is 2 Gbytes both for 32-bit and 64-bit programs.
  • Dynamic data. These are data for which memory is being allocated while executing the program. In C++, this allocation is usually performed by the malloc function or new operator. In 32-bit programs the size of dynamically allocated memory is restricted by 2 Gbytes, in 64-bit programs by 8 Tbytes.
  • Stack data. Memory is allocated for these data when entering a procedure and is released after exiting the procedure. The maximum size of program stack is 1 Gbyte both for 32-bit and 64-bit applications. (The stack size is defined by the linker and is 1 Mbyte by default)
For a 32-bit application launched in a 32-bit Windows, the total size of all the mentioned data types must not exceed 2 Gbytes. (Actually it is 1.75 Gbytes due to memory requirements of the operating system itself). A 32-bit program compiled with the switch /LARGEADDRESSAWARE:YES can allocate up to 3 Gbytes of memory if the 32-bit Windows is launched with the /3gb switch. The same 32-bit program launched in a 64-bit system can allocate about 4 Gbytes (actually about 3.5 Gbytes).
Note that the restrictions for maximum sizes of statically allocated memory and stack memory are the same for 32-bit and 64-bit Windows-applications. This is determined by the format of file type Portable Executable (PE) which is used in Windows to describe exe and dll files. You should keep in mind that these restrictions are imposed by the operating system itself and do not depend on the compiler you are using.

References

  1. Steve Lionel. Memory Limits for Applications on Windows
  2. Andrey Karpov, Evgeniy Ryzhkov. Lesson 2. Support of 32-bit applications in the 64-bit Windows environment

Комментариев нет:

Отправить комментарий