bad_alloc on vector.push() and vector.reserve()

Sayan Pal

I am trying to build a vector of GLfloat of size 772538368. While doing push_back() I am getting bad_alloc error.

After checking this question, I tried to reserve() memory for the vector. However, now I am getting the same error on the attempt of reserve() itself.

On my machine, vector.max_size: 1073741823, which is bigger than what I need. In other details, I am using VS 2015 on Windows 10. Also please find the relevant code snippets below.

What should I do to resolve this?

Relevant code snippet:

int main() {

    vector<GLfloat> targetVector; 
    targetVector.reserve(772538368); //Attempt2 to reserve. Also tried resize()

    vector<vector<vector<GLshort>>> my3DimensionalData;
    //build my3DimensionalData //no problem here.

    //targetVector.reserve(772538368); //Attempt1 to reserve.

    for (GLint rowIndex = 0; rowIndex < numberOfRows; rowIndex++)
    {
        for (GLint colIndex = 0; colIndex < numberOfCols; colIndex++)
        {
            for (GLint depthIndex = 0; depthIndex < numberOfDepths; depthIndex++)
            {
                //perform gymnastic here on my3DimensionalData and get data.

                /*initially I was getting bad_alloc while pushing back  
                 *elements in the following block.
                 *This led to Attempt1 and Attempt2 as shown above.
                 */
                targetVector.push_back(data1);
                targetVector.push_back(data2);
                ...
                targetVector.push_back(data7);
            }
        }
    }
}
MSalters

You're most likely going to need a 64 bit build. You need over 3 GB of contiguous memory, and that is almost all of your 4GB memory space.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

bad_alloc on vector.push() and vector.reserve()

From Dev

vector is throwing bad_alloc

From Dev

bad_alloc with QVector but not with std::vector

From Dev

Processing a large vector crashes the program with bad_alloc

From Dev

C++ vector std::bad_alloc error

From Dev

Strange std::bad_alloc in an already-created vector

From Dev

C++ vector std::bad_alloc error

From Dev

Processing a large vector crashes the program with bad_alloc

From Dev

C++ vector std::bad_alloc error in a program

From Dev

Thread safety std::vector push_back and reserve

From Dev

What is better: reserve vector capacity, preallocate to size or push back in loop?

From Dev

Thread safety std::vector push_back and reserve

From Dev

C++: vector<Foo*> with reserve(), push_back() destroying values

From Dev

Vector of vectors, reserve

From Dev

std::bad_alloc when allocating a new vector - what can I do

From Dev

Why does returning vector<string> throw std::bad_alloc exception?

From Dev

std::bad_alloc when allocating a new vector - what can I do

From Dev

std::bad_alloc when storing single characters from a text file into a vector C++

From Dev

How reserve in std::vector works + Accessing vector with []

From Dev

Undefined behavior for std::vector reserve()

From Dev

Does a vector assignment invalidate the `reserve`?

From Dev

Is std::vector::reserve(0); legal?

From Dev

reserve() Implementation for std::vector in STL

From Dev

MSVC 14 STL vector reserve

From Dev

time complexity of reserve on an empty vector vs. a deque and whether to use emplace or push_back

From Dev

How to preallocate(reserve) a priority_queue<vector>?

From Dev

Does std::vector::insert reserve by definition?

From Dev

array allocation followed by memcpy or vector with reserve?

From Dev

How does std::vector::reserve actually work?

Related Related

  1. 1

    bad_alloc on vector.push() and vector.reserve()

  2. 2

    vector is throwing bad_alloc

  3. 3

    bad_alloc with QVector but not with std::vector

  4. 4

    Processing a large vector crashes the program with bad_alloc

  5. 5

    C++ vector std::bad_alloc error

  6. 6

    Strange std::bad_alloc in an already-created vector

  7. 7

    C++ vector std::bad_alloc error

  8. 8

    Processing a large vector crashes the program with bad_alloc

  9. 9

    C++ vector std::bad_alloc error in a program

  10. 10

    Thread safety std::vector push_back and reserve

  11. 11

    What is better: reserve vector capacity, preallocate to size or push back in loop?

  12. 12

    Thread safety std::vector push_back and reserve

  13. 13

    C++: vector<Foo*> with reserve(), push_back() destroying values

  14. 14

    Vector of vectors, reserve

  15. 15

    std::bad_alloc when allocating a new vector - what can I do

  16. 16

    Why does returning vector<string> throw std::bad_alloc exception?

  17. 17

    std::bad_alloc when allocating a new vector - what can I do

  18. 18

    std::bad_alloc when storing single characters from a text file into a vector C++

  19. 19

    How reserve in std::vector works + Accessing vector with []

  20. 20

    Undefined behavior for std::vector reserve()

  21. 21

    Does a vector assignment invalidate the `reserve`?

  22. 22

    Is std::vector::reserve(0); legal?

  23. 23

    reserve() Implementation for std::vector in STL

  24. 24

    MSVC 14 STL vector reserve

  25. 25

    time complexity of reserve on an empty vector vs. a deque and whether to use emplace or push_back

  26. 26

    How to preallocate(reserve) a priority_queue<vector>?

  27. 27

    Does std::vector::insert reserve by definition?

  28. 28

    array allocation followed by memcpy or vector with reserve?

  29. 29

    How does std::vector::reserve actually work?

HotTag

Archive