when I try to create and resize a vector to hold the maximum number of items (vector::max_size()) i get a debug error during runtime :
“Invalid allocation size: 429467292”
Im wondering why u cant resize this, if max_size() should return the maximum number of item in the vector…
vector<int> vc;
vc.resize(vc.max_size());
I’d also try to enable LARGADRESSAWARE:On in VS2010, but that does not help. Wondering if this was even a right thoguth…
Anyone got a clue?
max_size()is the absolute maximum number of elements that the vector can store. Using the default allocator, this is usuallystd::numeric_limits<std::size_t>::max() / sizeof(T). That is, it’s the largest array of that type that you could possibly create.However, you could never actually allocate that large an array. The modules loaded by your program use up some of your program’s address space, as do the stacks of each thread. You’ll probably have other dynamically allocated objects in your program (either allocated by you or the runtime). These all contribute to address space fragmentation, which means that the largest contiguous block of available address space is much smaller than the total amount of available address space.
In short, it is not possible in practice to allocate a
vectorwithmax_size()elements.