I am testing to initialise a vector to the maximum possible size in runtime. Initially, I thought (size_t)-1
gives me a theoretical maximum while vector::max_size()
gives the true runtime maximum. After encountering application failure and asking this question, I have realised that is also another theoretical limit. Further research turns up this:
(maximum size a vector can reach) limited by the largest contiguous chunk of RAM your OS can allocate for you or the return value of vector<>::max_size(), whichever is smaller.
In vectors (and probably containers in general), how do I find this true runtime maximum? I am currently still midway through building up my application (it is a practice project), so I will accept any reasonably elegant and efficient solution that can give an exact value or close but safe approximation.