Why is std::vector so much slower then array pointer : <p>Im creating a Opengl font batch draw.</p>

<p>I want to know why my std::vector is so much slower then using a array pointer.</p>

<p>I have tried adding vector reserve and everything i can think of.</p>

<p>My FPS drops just over half when using vectors.</p>

<p>Vectors seem easier to manage and look nicer in code, but im really stuck on this.</p>

<p>Not sure if its something simple that i have missed?</p>

<p>Or is it better to just use array pointers?</p>

<pre><code>#ifdef USE_VECTORS
    std::vector&lt;Vertex&gt; m_vertices;
#else
    Vertex *m_pVertex;
    Vertex m_vertices[MAX_VERTICES];
#endif
</code></pre>

<p>drawing char function</p>

<pre><code>    void GLFont::drawChar(char c, int x, int y)
    {
        //  1------4
        //  |      |            1 = (x, y)
        //  |      |            2 = (x, y + charHeight)
        //  |      |            3 = (x + charWidth, y + charHeight)
        //  |      |            4 = (x + charWidth, y)
        //  |      |
        //  |      |
        //  2------3
        //

        const Glyph &amp;glyph = getChar(c);
        int charWidth = glyph.width;
        int charHeight = m_charHeight;

    #ifdef USE_VECTORS
        Vertex vert[] = {
            x, y,
            glyph.upperLeft[0], glyph.upperLeft[1],
            m_color[0], m_color[1], m_color[2], m_color[3],

            x, y + charHeight,
            glyph.lowerLeft[0], glyph.lowerLeft[1],
            m_color[0], m_color[1], m_color[2], m_color[3],

            x + charWidth, y + charHeight,
            glyph.lowerRight[0], glyph.lowerRight[1],
            m_color[0], m_color[1], m_color[2], m_color[3],

            x + charWidth, y,
            glyph.upperRight[0], glyph.upperRight[1],
            m_color[0], m_color[1], m_color[2], m_color[3]
        };
        //unsigned dataArraySize = sizeof(vert) / sizeof(Vertex);

        m_vertices.insert(m_vertices.end(), &amp;vert[0], &amp;vert[4]);

        ++m_numCharsToDraw;
    #else
         //1
        m_pVertex-&gt;x = x;
        m_pVertex-&gt;y = y;
        m_pVertex-&gt;s = glyph.upperLeft[0];
        m_pVertex-&gt;t = glyph.upperLeft[1];
        m_pVertex-&gt;r = m_color[0];
        m_pVertex-&gt;g = m_color[1];
        m_pVertex-&gt;b = m_color[2];
        m_pVertex-&gt;a = m_color[3];
        ++m_pVertex;

        // 2
        m_pVertex-&gt;x = x;
        m_pVertex-&gt;y = y + charHeight;
        m_pVertex-&gt;s = glyph.lowerLeft[0];
        m_pVertex-&gt;t = glyph.lowerLeft[1];
        m_pVertex-&gt;r = m_color[0];
        m_pVertex-&gt;g = m_color[1];
        m_pVertex-&gt;b = m_color[2];
        m_pVertex-&gt;a = m_color[3];
        ++m_pVertex;

        // 3
        m_pVertex-&gt;x = x + charWidth;
        m_pVertex-&gt;y = y + charHeight;
        m_pVertex-&gt;s = glyph.lowerRight[0];
        m_pVertex-&gt;t = glyph.lowerRight[1];
        m_pVertex-&gt;r = m_color[0];
        m_pVertex-&gt;g = m_color[1];
        m_pVertex-&gt;b = m_color[2];
        m_pVertex-&gt;a = m_color[3];
        ++m_pVertex;

        // 4
        m_pVertex-&gt;x = x + charWidth;
        m_pVertex-&gt;y = y;
        m_pVertex-&gt;s = glyph.upperRight[0];
        m_pVertex-&gt;t = glyph.upperRight[1];
        m_pVertex-&gt;r = m_color[0];
        m_pVertex-&gt;g = m_color[1];
        m_pVertex-&gt;b = m_color[2];
        m_pVertex-&gt;a = m_color[3];
        ++m_pVertex;

        if (++m_numCharsToDraw == MAX_CHARS_PER_BATCH)
        {
            drawTextEnd();
            drawBatchOfChars();
            drawTextBegin();
        }
    #endif
    }

void GLFont::drawBatchOfChars()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

#ifdef USE_VECTORS
    glVertexPointer(2, GL_INT, sizeof(Vertex), &amp;m_vertices[0].x);
    glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &amp;m_vertices[0].s);
    glColorPointer(4, GL_FLOAT, sizeof(Vertex), &amp;m_vertices[0].r);
#else
    glVertexPointer(2, GL_INT, sizeof(Vertex), &amp;m_vertices-&gt;x);
    glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &amp;m_vertices-&gt;s);
    glColorPointer(4, GL_FLOAT, sizeof(Vertex), &amp;m_vertices-&gt;r);
#endif

    glDrawArrays(GL_QUADS, 0, m_numCharsToDraw * 4);

    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);
}
</code></pre>
