Max vector size

Is there a maximum size a vector can reach? I know it's over 5 million chars (since I've already done that) but can it hold 25 million data points?
It's 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.

For example, on this dev box I have 256 GB RAM, but max_size is only 2G,

1
2
3
4
5
    for(std::vector<char>::size_type sz = 1;   ;  sz *= 2)
    {
        std::cerr << "attempting sz = " << sz << '\n';
        std::vector<char> v(sz);
    }
attempting sz = 536870912
attempting sz = 1073741824
attempting sz = 2147483648
aCC runtime: Uncaught exception of type "std::length_error".
aCC runtime: what(): vector<...>::vector(n,v): vector too long

Last edited on
Thanks! That's what I hoped.

cheers!
I have 256 GB RAM

Whyyyyyyyyyyyyy would you ever need that much???
Last edited on
Image and video processing springs to mind as one example. Decompress a blu-ray and see how much RAM you'd like then :p
Last edited on
When I asked mine, it also said 2GB. *Might* be an issue actually, is there any way to up that limit?
Decompress a blu-ray and see how much RAM you'd like then


And that kids, is a little thing we like to call pirating, or maybe something else but usually pirating.
Last edited on
Whyyyyyyyyyyyyy would you ever need that much???

it's not a personal computer.

Just re-ran it on a personal linux box: max_size is 18446744073709551615 (which happens to be std::numeric_limits<std::size_t>::max())

[...]
attempting sz = 4294967296
attempting sz = 8589934592
attempting sz = 17179869184 (my box starts swapping)
attempting sz = 34359738368 (that's too much, I only have 24 GB ram)
terminate called after throwing an instance of 'std::bad_alloc'

When I asked mine, it also said 2GB. *Might* be an issue actually, is there any way to up that limit?


max_size is typically literally the maximum integer value that can be used as the index, which means it cannot be surpassed without writing your own container or switching the development environment to one where size_t is 64 bit
Last edited on
And that kids, is a little thing we like to call pirating, or maybe something else but usually pirating.


I was thinking more professional animation studio like Pixar and what have you, but sure, pirates too.
Is there a maximum size a vector can reach?
Yes, vector::max_size()
http://en.cppreference.com/w/cpp/container/vector/max_size
I was thinking more professional animation studio like Pixar and what have you

You decompress Blu-ray for this? To quote ascii:
Whyyyyyyyyyyyyy???


@Cubbi: s***, guess I'll be doing that then.
You decompress Blu-ray for this?


No, we have the original that needs to be compressed.
Ahh, I see clarity now, gotcha. Pretty nice stuff, it'd make a heck of a hobby/job/both.
Topic archived. No new replies allowed.