How much memory should you be able to allocate?

前端 未结 8 1051
失恋的感觉
失恋的感觉 2020-12-31 17:36

Background: I am writing a C++ program working with large amounts of geodata, and wish to load large chunks to process at a single go. I am constrained to working with an a

8条回答
  •  失恋的感觉
    2020-12-31 18:36

    As much as the OS wants to give you. By default, Windows lets a 32-bit process have 2GB of address space. And this is split into several chunks. One area is set aside for the stack, others for each executable and dll that is loaded. Whatever is left can be dynamically allocated, but there's no guarantee that it'll be one big contiguous chunk. It might be several smaller chunks of a couple of hundred MB each.

    If you compile with the LargeAddressAware flag, 64-bit Windows will let you use the full 4GB address space, which should help a bit, but in general,

    • you shouldn't assume that the available memory is contiguous. You should be able to work with multiple smaller allocations rather than a few big ones, and
    • You should compile it as a 64-bit application if you need a lot of memory.

提交回复
热议问题