Regarding `std::vector`
===

I have an `std::vector<SomeType>`, whereas `SomeType` is a `struct` instantiated from various template parameters.

Eventually in my specific case it turns out to be a large structure (about 1MB). Allocating such a structure on the stack (i.e. using an automatic variable of this type) immediately leads to the stack overflow. But since `std::vector` allocates the memory on the heap - there *should* be no problem.

Surprisingly there **is** a problem with this. Specifically, the problem is with the initialization. I do the following:

    std::vector<SomeType> myVec;
    // ...
    myVec.resize(N);
    for (size_t i = 0; i < N; i++)
    {
        SomeType& x = myVec[i];
        // initialize it
    }

I get a stack overflow exception in `myVec.resize()`. Stepping inside `resize()` with the debugger revealed that if `resize()` causes the `vector` to grow - besides of allocating the memory it also initializes the new elements by "default values".

The "default value" is obtained by creating an **automatic** variable of the given type, using default (i.e. empty) constructor, and assigning the new element to it.

I wonder if there's a way to overcome this. I mean, tell `std::vector` not to initialize the new elements. But I'd like to achieve this **without generating unneeded code**.

I can think of using a `vector` of (smart/shared/scoped/unique) pointers to type. Or alternatively use `push_back` whereas each new element is allocated on heap. But all this inevitable involves extra code. Which is not justified.

Is there a way to achieve what I need? Whereas:

 - still using `std::vector<SomeType>`
 - No redundant heap allocations

Thanks in advance