«std :: bad_alloc»: я использую слишком много памяти?

Сообщение:

terminate called after throwing an instance of 'std::bad_alloc'
what():  std::bad_alloc

Я посмотрел на трассировку gdb, и это самый низкий уровень там метод, который я реализовал сам:

/*
 * get an array of vec3s, which will be used for rendering the image
 */
vec3 *MarchingCubes::getVertexNormalArray(){
    // Used the same array size technique as getVertexArray: we want indices to match     up
    vec3 *array = new vec3[this->meshPoints.getNumFaces() * 3]; //3 vertices per face

    int j=0;
    for (unsigned int i=0; i < (this->meshPoints.getNumFaces() * 3); i++) {
        realVec normal = this->meshPoints.getNormalForVertex(i);
 //     PCReal* iter = normal.begin();

        if (normal.size() >= 3) {
            array[j++] = vec3(normal[0], normal[1], normal[2]);
        }
        cout << i << " ";
    }

    return array;
}

Оператор cout, который вы видите выше, указывает, что он завершается после 7000+ итераций. Вышеупомянутая функция вызывается только один раз ближе к концу моего приложения. Перед вызовом вышеописанного я вызываю очень похожую функцию, это не вызывает проблем.

15
задан Rooster 4 December 2011 в 22:26
поделиться