Home > Net >  C - Can a vector's size become more than the system RAM?
C - Can a vector's size become more than the system RAM?

Time:09-19

If I keep on inserting elements in a vector until I get an out of memory exception. What is the limit to the final vector's size?

  1. Size of RAM
  2. Size of secondary memory because virtual memory is being used.

CodePudding user response:

This is entirely system dependent.

However, on typical desktop and server systems, allocations via new in a C application are allocations of virtual memory. If the system has swap space, then it is entirely possible to allocate more virtual memory than the size of physical RAM, so your #2 is closer to the truth.

Of course your vector cannot grow to fill all of physical memory plus swap, because some is needed for the OS itself, the rest of your program, other processes running on the system, etc. The system might be configured to impose other limits, such as a fixed limit on the amount of virtual memory available to any one process or user, and it might also reserve some amount of memory for system-critical uses.

  • Related