How to allocate a vector of type T with a length of N million in C++

1 Answer

0 votes
#include <iostream>
#include <vector>

using T = unsigned char;

int main() {
    size_t size = 10'000'000;  // 10 million

    std::vector<T> vec(size);

    std::cout << vec.size() << std::endl;
}


/*
run:

10000000

*/

 



answered Jul 1, 2025 by avibootz
...