Append an array pointer to an vector?

closed account (ENRX216C)
Hello,

I am using OpenGL and I have a function where you can provide vertices, these are provided as a smart pointer to an array of vertices. Now I want to append that array of vertices to an vector(so I can create one VBO instead of 1000).
But I am not sure how I would append the array pointer to the end of the vector.

Anyone can help me with that?

Thanks!

Edit:
Converting the array pointer to a vector is also ok as I can then append the vector to the other vector.(I think)
Last edited on
http://www.cplusplus.com/reference/vector/vector/vector/
has in example:
1
2
3
// the iterator constructor can also be used to construct from arrays:
int myints[] = {16,2,77,29};
std::vector<int> fifth( myints, myints + sizeof(myints) / sizeof(int) );

that calls the
1
2
3
4
// range (3)
template <class InputIterator>
vector( InputIterator first, InputIterator last,
        const allocator_type& alloc = allocator_type() );


Append to vector implies copying. If you create a vector from array and then append vector to an another vector, then you copy the vertices twice.

Manual copy avoids those:
http://www.cplusplus.com/reference/vector/vector/resize/
http://www.cplusplus.com/reference/algorithm/copy_n/
1
2
3
4
5
6
7
Vertice* foo = ... // pointer to array
size_t N = ... // vertices in array
std::vector<Vertice> bar = ... // existing vector

size_t S = bar.size();
bar.resize( S + N );
std::copy_n( foo, N, bar.begin() + S );
closed account (ENRX216C)
Thanks, but I ended up doing this:
textureTypes[triangles->rendertex].insert(textureTypes[triangles->rendertex].end(), triangles->vertices.get(), triangles->vertices.get() + triangles->size);
Where textureTypes is a map, and triangles a smart pointer to an array of floats.

Will above also be ok?
Topic archived. No new replies allowed.