Imagine I'm making a game
- I know it's going to run on a 64-bit system, on a 64-bit OS
- the memory budget for the game is fixed 2 (or 4) Gibibytes
Would that mean that out of 64 bits of Virtual Address Space
for the process, I would get 32bits left to play around however I want?
Could I - for example - for every container in the game (container = something like std::vector
) use VirtualAlloc
and MEM_RESERVE
2 Gibibytes of memory?
As new elements are added, new pages
(somewhere around 64K) are MEM_COMMIT
ed as necessary. As the container dies the memory is freed with VirtualFree
accordingly.
Out of curiosity:
Will this technically work?
Are there any performance reasons not to do this?
EDIT: Clarification: if there are 10000 containers in game, that would reserve 2GiB * 10000 memory - BUT the commited memory would be less than 2 (or 4) GiB.
Those 10000 containers could as well go up to be 2^16 containers (or however many the address space allows).