Can you allocate a very large single chunk of memory ( > 4GB ) in c or c++?

后端 未结 10 787
面向向阳花
面向向阳花 2020-12-02 10:46

With very large amounts of ram these days I was wondering, it is possible to allocate a single chunk of memory that is larger than 4GB? Or would I need to allocate a bunch o

10条回答
  •  攒了一身酷
    2020-12-02 11:11

    It depends on whether the OS will give you virtual address space that allows addressing memory above 4GB and whether the compiler supports allocating it using new/malloc.

    For 32-bit Windows you won't be able to get single chunk bigger than 4GB, as the pointer size is 32-bit, thus limiting your virtual address space to 4GB. (You could use Physical Address Extension to get more than 4GB memory; however, I believe you have to map that memory into the virtualaddress space of 4GB yourself)

    For 64-bit Windows, the VC++ compiler supports 64-bit pointers with theoretical limit of the virtual address space to 8TB.

    I suspect the same applies for Linux/gcc - 32-bit does not allow you, whereas 64-bit allows you.

提交回复
热议问题