Increasing the Memory Address Space

From RAD Studio
Jump to: navigation, search

Go Up to Managing Memory Index

This section describes how to extend the address space of the Memory Manager beyond 2 GB, on Win32.

Note: The default size of the user mode address space for a Win32 application is 2GB, but this can optionally be increased to 3GB on 32-bit Windows and 4GB on 64-bit Windows. The address space is always somewhat fragmented, so it is unlikely that a GetMem request for a single contiguous block much larger than 1GB will succeed - even with a 4GB address space.

To enable and use a larger address space

  1. Make sure the operating system supports a larger address space:
  2. Set the appropriate linker directive. The operating system must be informed through a flag in the executable file header that the application supports a user mode address space larger than 2GB, otherwise it will be provided with only 2GB. To set this flag, specify {$SetPEFlags IMAGE_FILE_LARGE_ADDRESS_AWARE} in the .dpr file of the application.
  3. Make sure that all libraries and third party components support the larger address space. With a 2GB address space the high bit of all pointers is always 0, so a larger address space may expose pointer arithmetic bugs that did not previously show any symptoms. Such bugs are typically caused when pointers are typecast to integers instead of cardinals when doing pointer arithmetic or comparisons.

Note: Memory allocated through the Memory Manager is guaranteed to be aligned to at least 8-byte boundaries. 16-byte alignment is useful when memory blocks will be manipulated using SSE instructions, but may increase the memory usage overhead. The guaranteed minimum block alignment for future allocations can be set with SetMinimumBlockAlignment.

See Also